Results 1 to 5 of 5

Thread: [RESOLVED] Save screenshot as jpeg

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    11

    Resolved [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")

  2. #2

    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.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Addicted Member Smartacus's Avatar
    Join Date
    Oct 2009
    Location
    Deep South, USA
    Posts
    196

    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
    ***************************************************
    Smartacus comes packaged "As Is With No Warranty"

    ************* Useful Links ******************
    FAQs: Index / Database Development / .NET CodeBank /
    Before Posting Here...MSDN

    MZTools (I love this tool when using VB6 - Free) /

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    11

    Re: [RESOLVED] Save screenshot as jpeg

    Thank you Smartacus

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