Obtaining array of bytes from PictureBox or PictureBox.Handle

  • Thread starter Thread starter Frustrated
  • Start date Start date
F

Frustrated

I have a third party DLL that communicates with a camera (Sony 1384)
and I have it working where the image is being displayed in a
picturebox. I am using VB.NET . There is a function in the legacy DLL
that allows me to send in the PictureBox Handle and the image is then
set to that handle.

I have the need to obtain the bytes from the image and store them in a
database. I tried using the following:

Private Function ConvertFromPictureBoxToArray(ByVal oPictureBox As
PictureBox) As Byte()
Dim oStream As New MemoryStream
Dim myImage As Image

If oPictureBox.Image Is Nothing Then
ConvertFromPictureBoxToArray = Nothing
Return Nothing
End If
Dim bmp As New Bitmap(oPictureBox.Image)
Try
bmp.Save(oStream, Imaging.ImageFormat.Bmp)
ConvertFromPictureBoxToArray = oStream.ToArray
bmp.Dispose()
oStream.Close()
Catch ex As Exception '//--Catch
MsgBox(ex.Message)
End Try
End Function

The problem is that PictureBox.Image is nothing and therefore I get no
data. I believe the legacy DLL is using DirectShow. Does anyone know
how to get the data, for instance, from the Handle or any other way.

Thanks,
Mike Dixon
 
Back
Top