ToBytes
Convert image to byte array
Source
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);