I have a method below to convert a PNG image file (known file size: under 1MB) to a byte array, Response class returns the byte array for a web request for image download.
The problem is ToArray(), which creates another copy in memory. GetBuffer() returns the underlying buffer, which provides better performance.
public byte[] imageToByteArray(System.Drawing.Image imageIn)
{
using(MemoryStream ms = new MemoryStream())
{
imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Png);
return ms.ToArray();
}
}
Can anyone provide the code using GetBuffer()?
.NET 4.5, ASP.NET,