gpt4 book ai didi

c# - 内存不足 Image.FromFile

转载 作者:IT王子 更新时间:2023-10-29 04:52:48 26 4
gpt4 key购买 nike

为什么我会遇到内存不足的错误?谢谢

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com