Results 1 to 3 of 3

Thread: Take a screenshot and save to bitmap

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2010
    Posts
    13

    Take a screenshot and save to bitmap

    Hi,

    I'm having an issue with some code I'm trying to write that takes a screenshot of the current screen and saves it to a bitmap file on my local PC.
    vb.net Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    2. Handles Button1.Click
    3.  
    4. Dim tempScreenshot = New Bitmap(Screen.PrimaryScreen.Bounds.Width, _
    5. Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb)
    6.  
    7. tempScreenshot.Save("C:\test.bmp")
    8.  
    9. End Sub

    I'm running Windows 7, could there be some type of administrator issue? I don't get any errors ... can someone please help since this must be something simple.
    Last edited by Hack; Dec 29th, 2010 at 06:53 AM. Reason: Added Highlight Tags

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Take a screenshot and save to bitmap

    Lets start with variables have to be declared AS something, so the first thing I would change would be
    vb.net Code:
    1. 'change from
    2. Dim tempScreenshot = New Bitmap(Screen.PrimaryScreen.Bounds.Width, _
    3. Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb)
    4. 'change to
    5. Dim tempScreenshot As New Bitmap(Screen.PrimaryScreen.Bounds.Width, _
    6. Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb)
    Moved To VB.NET

  3. #3
    Frenzied Member MattP's Avatar
    Join Date
    Dec 2008
    Location
    WY
    Posts
    1,227

    Re: Take a screenshot and save to bitmap

    Quote Originally Posted by Hack View Post
    Lets start with variables have to be declared AS something
    It's inferred AS Bitmap and perfectly acceptable code.

    -----

    The problem is that all that's been done is creating a new Bitmap with the dimensions of the primary screen. You need to create a graphics object and get the contents of the screen.

    Code:
            Dim tempScreenshot = New Bitmap(Screen.PrimaryScreen.Bounds.Width,
                                            Screen.PrimaryScreen.Bounds.Height,
                                            PixelFormat.Format32bppArgb)
    
            Dim g = Graphics.FromImage(tempScreenshot)
            g.CopyFromScreen(0, 0, 0, 0, tempScreenshot.Size)
            g.Dispose()
            tempScreenshot.Save("C:\Temp\Test.bmp")

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