c# - Convert image to byte array using MemoryStream.GetBuffer via ASP.NET -
i have method below convert png image file (known file size: under 1mb) byte array, response class returns byte array web request image download.
the problem toarray(), creates copy in memory. getbuffer() returns underlying buffer, 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 provide code using getbuffer()?
.net 4.5, asp.net,
you should save file directly output steam of asp.net
public actionresult downloadfile() { image imagein = getimage(); imagein.save(response.outputstream, imageformat.png); return new httpstatuscoderesult(httpstatuscode.ok); }
Comments
Post a Comment