ExtensionMethod.NET Home of 876 C#, Visual Basic, F# and Javascript extension methods


Convert image to byte array


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();


Image image = ...;
byte[] imageBytes = image.ToBytes(ImageFormat.Png);

Author: Lucas

Submitted on: 7 mrt 2008

Language: C#

Type: System.Image

Views: 5565