Convert an image to a byte array.

July 16, 2010 - 10:14

You should have your image stored in the "myimage" variable, and then use the below code to convert to a .Png format and save into the "mybytearray" array.

Dim myimage as Image 'this should contain your image.

Dim mybytearray As Byte()
Dim ms As System.IO.MemoryStream = New System.IO.MemoryStream
myimage.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
mybytearray = ms.ToArray()


For alternative imageformats you can use Imageformat.bmp,Imageformat.gif,Imageformat.jpeg etc.



© 2011 simplevb.net