为什么我会遇到内存不足的错误?谢谢
if (File.Exists(photoURI))
{
FileStream fs = new FileStream(photoURI, FileMode.Open, FileAccess.Read);
Image img = Image.FromStream(fs);
fs.Close();
}
最佳答案
在Image.FromFile
文档中,一个 OutOfMemoryException
可以抛出如果:
The file does not have a valid image format.
-or-
GDI+ does not support the pixel format of the file.
检查你的图像格式。
此外,如果您想在加载图像后立即关闭流,您必须复制图像。看看here . GDI+ 必须在图像的整个生命周期内保持流打开。
关于c# - 内存不足 Image.FromFile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3848132/