C# – Convert bitmap into byte array

Updated on     Kisan Patel


c# – Convert a bitmap into a byte array
c# – Convert Bitmap to byte
C# convert a BitMap to Byte[] Bitmap to byte array in C# – .NET


There are a couple ways.

Using ImageConverter Class

public static byte[] ImageToByte(Image img)
    ImageConverter converter = new ImageConverter();
    return (byte[])converter.ConvertTo(img, typeof(byte[]));

This one is convenient because it doesn’t require a lot of code.

Using MemoryStream Class

public static byte[] ImageToByte2(Image img)
    byte[] byteArray = new byte[0];
    using (MemoryStream stream = new MemoryStream())
         img.Save(stream, System.Drawing.Imaging.ImageFormat.Png);

         byteArray = stream.ToArray();
    return byteArray;


Leave a Reply