ASP.NETMVC3での画像アップロードのシナリオがあります。
コントローラ
public ActionResult Upload(IEnumerable<HttpPostedFileBase> images, SomeViewModel model) { foreach(var i 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(); }
そのため、クライアントからHttpPostedFileBaseとして画像を受け取ります。byte[]fileBytesをimageManagerのResizeメソッドに渡します。画像マネージャは新しいWebImageインスタンスを作成してから、画像のサイズを変更して、もう一度byte[]に変換します。
このコードをデバッグするとき、wi.GetBytes()行を渡すと、メモリ使用量が大幅に増加します(少なくとも500MB)。10MBの画像をアップロードしています。小さいサイズの写真(〜1.5mb)をアップロードする場合、メモリ消費は正常です。
これの原因は何である可能性があり、これは何らかの方法で修正できますか?
ありがとうございました