Wednesday, July 29, 2009

byte array to bitmap

http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/e57f7731-c703-4c17-b1a2-32b155f9b745
 
public static Bitmap BytesToBitmap(byte[] byteArray)
{
using (MemoryStream ms = new MemoryStream(byteArray))
{
Bitmap img = (Bitmap)Image.FromStream(ms);
return img;
}
}


TypeConverter tc = TypeDescriptor.GetConverter(typeof(Bitmap));

Bitmap bitmap1 = (Bitmap)tc.ConvertFrom(byteArray);

Or,



ImageConverter ic = new ImageConverter();

Image img = (Image)ic.ConvertFrom(byteArray);

Bitmap bitmap1 = new Bitmap(img);

No comments: