使用System.Drawing.Image加载图像时内存不足 [英] Out of memory on loading a Image with System.Drawing.Image

查看:1056
本文介绍了使用System.Drawing.Image加载图像时内存不足的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

System.Drawing.Image original = System.Drawing.Image.FromFile(photo);

这就是我遇到问题的代码内存不足

That's the code where i have the problem "Out of memory."

photo 是图片的路径,其大小 6400x6400

"photo" is a path of an image which the size is 6400x6400.

有没有人知道这件事?

推荐答案

这是C#吗?我想答案可能就在这里。

Is this C#? I think the answer may be here.

内存不足Image.FromFile

用户的最佳答案: https://stackoverflow.com/users/31158/jordao


图片中。 FromFile 文档,如果出现以下情况,则可以抛出 OutOfMemoryException

In the Image.FromFile documentation, an OutOfMemoryException can be throw if:


该文件没有有效的图像格式。

The file does not have a valid image format.

- 或 -

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.

另一个最佳答案和线程:

Another top answer and thread to consider then:

Out of Memory exception在System.Drawing.Image.FromFile()

来自用户: https://stackoverflow.com/users/22656/jon-skeet


值得知道OutOfMemoryException并不总是真的意味着内存不足 - 尤其是在处理文件时。我相信如果你出于某种原因用完手柄也会发生这种情况。

It's worth knowing that OutOfMemoryException doesn't always really mean it's out of memory - particularly not when dealing with files. I believe it can also happen if you run out of handles for some reason.

你完成它们之后是否处理了所有的位图?对于单个图像,这是否会重复发生?

Are you disposing of all your bitmaps after you're done with them? Does this happen repeatably for a single image?

另外,我会添加 - 您使用您的代码保存此文件并尝试在另一个图像查看器中查看它?如果创建不正确,可能会损坏。

Also, I would add- have you saved this file out using your code and tried to view it in another image viewer? It may be corrupt if it is being created incorrectly.

这篇关于使用System.Drawing.Image加载图像时内存不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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