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,

creating byte array stream

fastest way convert image byte array

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

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -