Page 1 of 1

Saving VB6 picturebox image content to file?

Posted: Wed Aug 29, 2007 1:49 pm
by mikeincinci
Using VB6, I use "objCamera.DrawFrame oNewFrame, pic1.hwnd" to update a picturebox with the current frame image. How can I save this image to file?

Re: Saving VB6 picturebox image content to file?

Posted: Thu Aug 30, 2007 6:15 pm
by Birch
This is inefficient, but should work.

Code: Select all

 
         ' save VGA image from V100 camera
         ' assumes control named pic1,size 640x480, scalemode = pixel,autoredraw = true
         ' assumes camera frame of oNewFrame exists and is valid

         Dim arrayImageBuf(921600) As Byte  ' 640 x 480 x 3 = 921600 bytes for 24 bit depth
         Dim pxRed, pxGreen, pxBlue
         Dim x,y
         
         ' render the frame image into a buffer
         ' 640x480, auto calculate byte span, 24 bits per pixel
         oCamera.GetFrameImage oNewFrame, 640, 480, 0, 24, arrayImageBuf(1)

            ' copy image from buffer into picturebox control 
            ' inefficient, SetBitmapBits from gdi32.dll would be faster
            For x = 0 To 639
              For y = 0 To 479
                pxRed = arrayImageBuf((((y * 640) + x) * 3) + 3)
                pxGreen = arrayImageBuf((((y * 640) + x) * 3) + 2)
                pxBlue = arrayImageBuf((((y * 640) + x) * 3) + 1)
                pic1.PSet (x, y), RGB(pxRed, pxGreen, pxBlue)
              Next y
            Next x

         ' save the image to a file
         SavePicture pic1.Image, "c:\Example.bmp" 

Re: Saving VB6 picturebox image content to file?

Posted: Tue Sep 04, 2007 3:10 pm
by mikeincinci
Thanks! That works fine for me!