how to convert an image in picturebox to byte array?

pavansagar

Member
Joined
Jan 11, 2006
Messages
8
Programming Experience
Beginner
I have an image in a picturebox.I want to convert that image to an array of bytes.
I am trying in this way

Dim picObj As Object
picObj = picturebox.Image
Dim picbit As Byte() = CType(picObj, Byte())

but it is showing the error as follows
"Specified cast is not valid"

please help me in this regard.
thank you,
pavansagar
 
Save Image to a MemoryStream and get the bytes from there:
VB.NET:
Dim ms As New IO.MemoryStream
PictureBox1.Image.Save(ms, Imaging.ImageFormat.Jpeg)
Dim bytes() As Byte = ms.GetBuffer()
 
Back
Top