[RESOLVED] Save screenshot as jpeg
Hello, I'm using the below code to capture desktop screenshot, it is working but doesn’t encode the screenshot result in real jpeg, I came to know that from the huge size of the saved jpeg file around 5MB!!!
Can anyone please help in fixing this issue?
Code:
Dim ScreenSize As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
Dim screenGrab As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(screenGrab)
g.CopyFromScreen(New Point(0, 0), New Point(0, 0), ScreenSize)
screenGrab.Save("C:\Screenshot.jpeg")
Re: Save screenshot as jpeg
Well obviously its not going to work:
Code:
Dim screenGrab As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
You're creating a new Bitmap
I once heard a quote: "You can put a Tuxedo on a goat, but it's still a goat."
Basically, you can save a file as a jpeg, but if you create it as a bitmap, it's still a bitmap.
Re: Save screenshot as jpeg
The Save method is overloaded. You can specify the file format as well as the path. Let Intellisense guide you. Put the cursor at the end of that line and hit Backspace and Intellisense should popup and provide you with your options. If it doesn't then just hit Ctrl+Space.
Re: Save screenshot as jpeg
Code:
Private Sub SaveImage()
Dim BMPname As String
Dim graph As Graphics = Nothing
Try
Dim bmp As Bitmap = New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
graph = Graphics.FromImage(bmp)
graph.CopyFromScreen(0, 0, 0, 0, bmp.Size)
BMPname = "C:\Screenshot.jpeg"
bmp.Save(BMPname,System.Drawing.Imaging.ImageFormat.Jpeg)
Finally
graph.Dispose()
End Try
End Sub
Re: [RESOLVED] Save screenshot as jpeg