Image to ByteArray and ByteArray to Image using C#

Image to Byte[]

private static byte[] GetImageByteArr(System.Drawing.Image img)
byte[] ImgByte;
using (MemoryStream stream = new MemoryStream())
img.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
ImgByte = stream.ToArray();
return ImgByte;

Byte[] to Image

private Image bytetoimg(byte[] bytearr)
Image newImage;
MemoryStream ms=new MemoryStream(bytearr,0,bytearr.Length);
return newImage;


1 comment:

Padmakar said...


I tried converting bytearray to image using the method u suggested. It is throwing the execption "Argument exception :Parameter is not valid."
Can you please provide us a solution for this.