In this short code snippet article I will explain with an example, how to convert System.Drawing.Image object to Array of Bytes or Byte Array using C# and VB.Net.
 
 
Namespaces
You will need to import the following namespace.
C#
using System.Drawing;
 
VB.Net
Imports System.Drawing
 
 
Convert System.Drawing.Image to Byte Array using C# and VB.Net
The Image File is read into an Image object using the FromFile function. Then using the ImageConverter class object the Image object is converted to Array of Bytes or Byte Array.
C#
//Read Image File into Image object.
Image img = Image.FromFile("C:\\Koala.jpg");
 
//ImageConverter Class convert Image object to Byte array.
byte[] bytes = (byte[])(new ImageConverter()).ConvertTo(img, typeof(byte[]));
 
VB.Net
'Read Image File into Image object.
Dim img As Image = Image.FromFile("C:\Koala.jpg")
 
'ImageConverter Class convert Image object to Byte array.
Dim bytes As Byte() = CType((New ImageConverter()).ConvertTo(img, GetType(Byte())), Byte())
 
 
Downloads