Friday, February 4, 2011

Code for Image to Byte Array and Byte Array to Image Converter using C#

Convert Image to byte[] array
public byte[] imageToByteArray(System.Drawing.Image imageIn)
{
MemoryStream ms = new MemoryStream();
imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);
return  ms.ToArray();
}
Convert byte[] array to Image
public Image byteArrayToImage(byte[] byteArrayIn)
{
MemoryStream ms = new MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
return returnImage;
}

1 comment:

Shahnawaz said...

Well this dosen't work in silverlight 3 or 4