I want to make a program that will take a screenshot inside the bounds of a rectangle. Is there a way to do this? I don't want to use sendkeys{"(prtsc)"} because that doesn't take a screenshot of only an area on the form.
Could someone please help?
Printable View
I want to make a program that will take a screenshot inside the bounds of a rectangle. Is there a way to do this? I don't want to use sendkeys{"(prtsc)"} because that doesn't take a screenshot of only an area on the form.
Could someone please help?
I told you it would be easier to just do it in Photoshop!
I'm doing something different now, and I'm not good in photoshop. How do you use DirectDraw?
Actually, I saw someone post in a different thread talking about putting multiple pictures within a picturebox, I don't know if I remember correctly, I actually think it might have been you.
Have you tried your good friend google yet?
search "screen area capture vb.net example" and the very first entry returned is a codebank article on this very forum for a class which will capture either the whole screen or part of the screen.
Alright, I tried google, and I tried a source code from a site
This works fine, the only problem is that I can't get it to take the screenshot of the rectangle area. I think it's because it's taking a screenshot of the bounds on the screen. Do you think that my be the problem???Code:Dim bounds As Rectangle
Dim screenshot As System.Drawing.Bitmap
Dim graph As Graphics
bounds = Me.RectangleShape1.Bounds
screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
graph = Graphics.FromImage(screenshot)
graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
PictureBox1.Image = screenshot
I'm not sure what that code is going to do - partly because it is incomplete - what is Rectangleshape1?
Have you tried the codebank article This is the first hit returned when I searched google?
The code there includes a function "CaptureDeskTopRectangle", which is described in comments :
So you just tell it which part of the screen you want to capture and it returns a bitmap object. That sounds pretty close to what you are after.Code:'/ Returns BitMap of the region of the desktop, similar to CaptureWindow, but can be used to
'/ create a snapshot of the desktop when no handle is present, by passing in a rectangle
'/ Grabs snapshot of entire desktop, then crops it using the passed in rectangle's coordinates
What the code does is it sets up in area on the screen to take the screenshot and then creates the screenshot, and puts in it a picturebox. The only problem is that if rectangleshape1.top=50 and rectangleshape1.left=100 then that's where the rectangle's bounds will be registered on the whole screen instead of on the form. How can I make it only register on the form?
So are you saying you want to capture an image of a form in your own application, rather than a screenshot?
If so, you can convert points within your form to screen co-ordinates using the form's "PointToScreen" function, for example if you want to get the screen co-ordinates for a point 50, 100 on your own form you would use :
Code:Me.PointToScreen(New Point(50, 100))
Ok, I'll try that, but here's a code I used that works.
But if I use pointtoscreen, will that take a screenshot of the object within the form? or only on the screen?Code:With RectangleShape1
.Top = Me.Top + 31
.Left = Me.Left + 4
End With
Dim bounds As Rectangle
Dim screenshot As System.Drawing.Bitmap
Dim graph As Graphics
bounds = RectangleShape1.Bounds
screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
graph = Graphics.FromImage(screenshot)
graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
PictureBox1.Image = screenshot
PointToScreen will convert the co-ordinates from those within a form to the absolute position on the screen.
For example - say your form appears 100 pixels in from the left of the screen and 10 pixels down. You are interested in capturing a square who's top-left co-ordinate within the form is 15,15.
If you pass the point 15,15 into the form's point to screen, it will return the actual position of that point in relation to the screen's top left corner, ie 115, 25
If the code in that class in the codebase article works in screen co-ordinates then this is how you convert co-ordinates from your form's client area to the screen's co-ordinates.
So in aswer to your question, using these co-ordinates will mean that the capture grabs the part of the screen that corresponds to the section of your form that you have told it to grab.