ToBytes

public static byte[] ToBytes(this Image image, ImageFormat format)
{
	if(image == null)
		throw new ArgumentNullException("image");
	if(format == null)
		throw new ArgumentNullException("format");

	using(MemoryStream stream = new MemoryStream())
	{
		image.Save(stream, format);
		return stream.ToArray();
	}
}
Example:
Image image = ...;
byte[] imageBytes = image.ToBytes(ImageFormat.Png);

Description

Convert image to byte array

Details

Double click on the code to select all.

 

;