内存不足Image.FromFile的 [英] out of memory Image.FromFile

查看:1279
本文介绍了内存不足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, an OutOfMemoryException 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屋!

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