System.Drawing.Image.FromFile() 上的内存不足异常 [英] Out Of Memory exception on System.Drawing.Image.FromFile()

查看:73
本文介绍了System.Drawing.Image.FromFile() 上的内存不足异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个创建缩略图的图像上传器和裁剪器,我偶尔会在以下行中收到内存不足异常:

I have an image uploader and cropper which creates thumbnails and I occasionally get an Out Of Memory exception on the following line:

Dim bm As Bitmap = System.Drawing.Image.FromFile(imageFile)

错误的发生很小而且非常罕见,但我总是想知道可能是什么原因造成的.imageFile 变量只是图像路径的 Server.MapPath.

The occurance of the error is tiny and very rare, but I always like to know what might be causing it. The imageFile variable is just a Server.MapPath to the path of the image.

我很好奇是否有人以前遇到过这个问题,如果他们知道可能是什么原因导致的?也许是图片的大小?

I was curious if anyone had experience this issue previously and if they had any ideas what might be causing it? Is it the size of the image perhaps?

如有必要,我可以发布代码和我拥有的任何支持信息,但很想听听人们对此的意见.

I can post the code if necessary and any supporting information I have, but would love to hear people's opinions on this one.

推荐答案

值得知道的是 OutOfMemoryException 并不总是真的意味着它的内存不足 - 尤其是在处理文件时.我相信如果您出于某种原因用完了句柄,也会发生这种情况.

It's worth knowing that OutOfMemoryException doesn't always really mean it's out of memory - particularly not when dealing with files. I believe it can also happen if you run out of handles for some reason.

在处理完所有位图后,您是否将其处理掉?单个图像是否会重复发生这种情况?

Are you disposing of all your bitmaps after you're done with them? Does this happen repeatably for a single image?

这篇关于System.Drawing.Image.FromFile() 上的内存不足异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆