Click here to Skip to main content
15,919,479 members
Please Sign up or sign in to vote.
4.00/5 (3 votes)
See more:
hi all i am taking screen shots through coding, but the problem is i want to set bounds, example i want to set the my scrren screen shots position like x,y

this is the coding i am using for it

VB
Dim b As Bitmap = New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height, Imaging.PixelFormat.Format32bppArgb)
       Dim gfx As Graphics = Graphics.FromImage(b)
       gfx.CopyFromScreen(My.Computer.Screen.Bounds.X, My.Computer.Screen.Bounds.Y, 0, 94, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy)
       path = "C:\Documents and Settings\Nano\My Documents\My Pictures"
       b.Save("my2.jpg", Imaging.ImageFormat.Jpeg)
Posted

1 solution

You have everything to do that. Instead of My.Computer.Screen.Bounds use some greater values of sourceX and sourceY which will define offsets from the top and left bounds of the screen and reduce size to required size. In this way, you will copy a smaller source rectangle representing a subset of the screen pixels.

See http://msdn.microsoft.com/en-us/library/cdcw1c3b.aspx[^].

—SA
 
Share this answer
 
Comments
sameertm 8-May-11 17:13pm    
can you give me some sample coding for this, or you can edit my coding and show me some example
Sergey Alexandrovich Kryukov 8-May-11 20:30pm    
You already have this code. Just use the different parameters in CopyFromScreen:
CopyFromScreen(
My.Computer.Screen.Bounds.X + myRectangle.Left,
My.Computer.Screen.Bounds.Y + myRectangle.Top,
0, 0,
myRectangle.Size,
CopyPixelOperation.SourceCopy);

If myRectangle is smaller than Screen it will be a part of the screen, that's it.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900