I don't know why you want the image to be a byte array, but think about Memorystreams. This example is provided in the vb.net file:
Private Function GetImageByteArray(im As Image) As Byte() Try Using st As System.IO.MemoryStream = New System.IO.MemoryStream im.Save(st, Imaging.ImageFormat.Raw) Return st.ToArray End Using Finally GC.Collect() End Try End Function private byte[] GetImageByteArray(Image im) { try { using(MemoryStream st = new MemoryStream()) { im.save(st, ImageFormat.Raw); return st.toarray(); } } finally { GC.Collect(); } }
But the described problem is more like converting data from a string to a byte array.
image im; using memorystream st = new memorystream(Convert.FromBase64String(data.substring(data.firstindexof(','))) {im = image.fromstream(st);}
source share