Results 1 to 12 of 12

Thread: [RESOLVED] Take screenshot of Bounds?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2009
    Posts
    358

    Resolved [RESOLVED] Take screenshot of Bounds?

    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?

  2. #2
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Take screenshot of Bounds?

    I told you it would be easier to just do it in Photoshop!

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2009
    Posts
    358

    Re: Take screenshot of Bounds?

    Quote Originally Posted by keystone_paul View Post
    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.

  4. #4
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Take screenshot of Bounds?

    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.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2009
    Posts
    358

    Re: Take screenshot of Bounds?

    Quote Originally Posted by keystone_paul View Post
    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
    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
    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???

  6. #6
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Take screenshot of Bounds?

    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 :

    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
    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.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2009
    Posts
    358

    Re: Take screenshot of Bounds?

    Quote Originally Posted by keystone_paul View Post
    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 :

    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
    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.
    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?

  8. #8
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Take screenshot of Bounds?

    So are you saying you want to capture an image of a form in your own application, rather than a screenshot?

  9. #9
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Take screenshot of Bounds?

    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))

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2009
    Posts
    358

    Re: Take screenshot of Bounds?

    Quote Originally Posted by keystone_paul View Post
    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.
    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
    But if I use pointtoscreen, will that take a screenshot of the object within the form? or only on the screen?

  11. #11
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Take screenshot of Bounds?

    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.

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2009
    Posts
    358

    Re: Take screenshot of Bounds?

    Quote Originally Posted by keystone_paul View Post
    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.
    Alright, thanks for the help Paul. If you know anything about adding frames to a video file, look for my next thread.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width