Convert Image to Byte Array
May 10, 2013 at 1:30 AM
—
admin
as the subject says ... if you want to convert an Image to an array of bytes to save it in the database or in a file or send it to a web service or another application , just put the following extension method in a static class and call it from the Image object like :
byte[] mImageBytes = img.ToBytes(ImageFormat.Png);
public static byte[] ToBytes(this Image image, ImageFormat format)
throw new ArgumentNullException("image");
throw new ArgumentNullException("format");
using (MemoryStream stream = new MemoryStream())
image.Save(stream, format);
ac24120f-3402-49cd-871c-abb5deec32fb|0|.0|96d5b379-7e1d-4dac-a6ba-1e50db561b04
Posted in: .NET | IT
Tags: