|
-
Dec 29th, 2010, 06:33 AM
#1
Thread Starter
New Member
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:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
Dim tempScreenshot = New Bitmap(Screen.PrimaryScreen.Bounds.Width, _
Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb)
tempScreenshot.Save("C:\test.bmp")
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
-
Dec 29th, 2010, 06:58 AM
#2
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:
'change from
Dim tempScreenshot = New Bitmap(Screen.PrimaryScreen.Bounds.Width, _
Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb)
'change to
Dim tempScreenshot As New Bitmap(Screen.PrimaryScreen.Bounds.Width, _
Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb)
Moved To VB.NET
-
Dec 29th, 2010, 10:18 AM
#3
Re: Take a screenshot and save to bitmap
 Originally Posted by Hack
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|