asp.net - WebImage and large memory consumption -


we have scenario of image upload in asp.net mvc3.

  • controller

    public actionresult upload(ienumerable<httppostedfilebase> images, someviewmodel model) {   foreach(var in images)   {     ...      byte[] filebytes = i.inputstream.getbytesarray();      byte[] image = _imagemanager.resize(filebytes, maximagewidth, maximageheight, true);       ...   } } 
  • imagemanager

    public byte[] resize(byte[] content, int width, int height, bool preservear = true) {   if (content == null)     return null;    webimage wi = new webimage(content);    wi = wi.resize(width, height, preserveaspectratio);    return wi.getbytes(); } 

so recieve image client httppostedfilebase. pass byte[] filebytes resize method of imagemanager. image manager creating new webimage instance, resize image , transform byte[] again.

when debugging code, @ moment pass wi.getbytes() line, memory usage raises drastically (for @ least 500mb). i`m uploading image of 10mb. when uploading smaller size photos (~1.5mb) memory consumption normal.

what can cause of this, , can fixed somehow?

thank you

under hood webimage uses system.drawing.image.fromstream take original image stream , turn array of bytes. tried taking 6.0mb jpg , calling method on , got stream 6.0mb in it. if ask bmp 172mb byte aray

i suspect you're uploading compressed image (e.g. png / jpg) , call getbytes causing decompressed bytes of image made available. when decompressed it's raw form image substantially larger. not can around short of dealing stream objects whole way never load memory @ once.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -