Results 1 to 2 of 2

Thread: Convert Bitmap to JPG

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2008
    Location
    South Africa
    Posts
    395

    Convert Bitmap to JPG

    Hi,
    I borrwed some code to capture a image with the onboard Web Cam of my Laptop. It works fine, but is is saving the image as a Bitmap, how can i convert the image to a JPG file?

    Here is some part of the code.

    Code:
     Public Function copyFrame(ByVal src As PictureBox, ByVal rect As RectangleF) As Bitmap
            If iRunning Then
                Dim srcPic As Graphics = src.CreateGraphics
                Dim srcBmp As New Bitmap(src.Width, src.Height, srcPic)
                Dim srcMem As Graphics = Graphics.FromImage(srcBmp)
                Dim HDC1 As IntPtr = srcPic.GetHdc
                Dim HDC2 As IntPtr = srcMem.GetHdc
                BitBlt(HDC2, 0, 0, CInt(rect.Width), _
                  CInt(rect.Height), HDC1, CInt(rect.X), CInt(rect.Y), 13369376)
    
                '' Capture Image as Bitmap
                copyFrame = CType(srcBmp.Clone(), Bitmap)
                'Clean Up 
                srcPic.ReleaseHdc(HDC1)
                srcMem.ReleaseHdc(HDC2)
                srcPic.Dispose()
                srcMem.Dispose()
            Else
                MessageBox.Show("Camera Is Not Running!")
            End If
        End Function

  2. #2
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Convert Bitmap to JPG

    Just like this:
    Code:
    ' Capture Image as Bitmap
    copyFrame = CType(srcBmp.Clone(), Bitmap)
    ' Add this:
    Dim img As Image = Image.FromHbitmap(copyFrame.GetHbitmap)
    img.Save("filename.jpeg", Drawing.Imaging.ImageFormat.Jpeg)

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