内存不足Image.FromFile的 [英] out of memory Image.FromFile
问题描述
为什么说我得到了内存不足的错误?谢谢
如果(File.Exists(photoURI))
{
的FileStream FS =新的FileStream(photoURI,FileMode.Open,FileAccess.Read);
图片IMG = Image.FromStream(FS);
fs.Close();
}
在 Image.FromFile
文档,一个 OutOfMemoryException异常
可以抛出,如果:
该文件没有有效的图像格式。
- 或 -
GDI +不支持的文件的像素格式。
块引用>检查您的图像格式。
另外,如果你想加载图像后立即关闭流,你的必须的使图像的副本。看看<一个href=\"http://stackoverflow.com/questions/3661799/file-delete-failing-when-image-fromfile-was-called-prior-it-despite-making-copy/3661892#3661892\">here. GDI +必须保持流开放的图像的使用寿命。
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(); }
解决方案In the
Image.FromFile
documentation, anOutOfMemoryException
can be throw if:The file does not have a valid image format.
-or-
GDI+ does not support the pixel format of the file.
Check your image format.
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的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!