本文介绍了内存不足 Image.FromFile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么会出现内存不足错误?谢谢
Why is it that I'm getting an out of memory error? Thank you
if (File.Exists(photoURI))
{
FileStream fs = new FileStream(photoURI, FileMode.Open, FileAccess.Read);
Image img = Image.FromStream(fs);
fs.Close();
}
推荐答案
在 Image.FromFile
文档,如果:
In the Image.FromFile
documentation, an OutOfMemoryException
can be throw if:
该文件没有有效的图像格式.
-或-
GDI+ 不支持文件的像素格式.
GDI+ does not support the pixel format of the file.
检查您的图像格式.
此外,如果您想在加载图像后立即关闭流,您必须制作图像的副本.看看 这里.GDI+ 必须在图像的整个生命周期内保持流打开.
Also, if you want to close the stream right after loading the image, you must make a copy of the image. Take a look here. GDI+ must keep the stream open for the lifetime of the image.
这篇关于内存不足 Image.FromFile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!