Image.FromFile()抛出内存不足异常 [英] Image.FromFile() throws out of memory exception

查看:357
本文介绍了Image.FromFile()抛出内存不足异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试显示136MB大小的.tif图像。但Image.FromFile(...)继续抛出内存异常我手动将虚拟内存的大小增加到4GB左右,但无济于事。



我检查过图像文件以确保它没有损坏,我可以通过操作系统附带的其他编辑器看到图像。

我的操作系统是Windows-XP Service Pack 3,我使用的是Visual Studio 2008.





提前谢谢。

I am trying to display a .tif image of 136MB size. But Image.FromFile(...) keeps on throwing out of memory exception I manually increased the size of the virtual memory to around 4GB but to no avail.

I have checked image file to make sure that it is not corrupted and I can see the image through other editors that come with my operating system.
My operating system is Windows-XP Service pack 3 and I am using Visual Studio 2008.

!
Thanks in advance.

推荐答案

我从未尝试过136MB的TIF,但是我处理的BMP和JPG文件远远大于没有问题的文件。编辑现有代码,并向我们显示发生异常的方法 - 用代码块小部件将其括起来以保留格式。
I've never tried a 136MB TIF, but I have dealt with BMP and JPG files that are much larger than that without problems. Edit your existing code, and show us the method that the exception is occurring in - enclose it with the "code block" widget to preserve the formatting.


ephrem33写道:
ephrem33 wrote:

一个136MB大小的.tif图像

a .tif image of 136MB size





这是一个大的!我建议你转换成更轻的图像类型,然后尝试使用它。



此外,像这样的大图像很难保存和检索。

否则,看看这个帖子,听起来与建议的解决方案类似:用于.NET的双色调(TIFF)图像转换器 [ ^ ]


我同意Sandeep。



我为Windows CE编写了一次相机驱动程序。我对图像的大多数经验都来自Windows CE / Mobile,所以我无法完全说出Win32中发生了什么,但我认为有相似之处。



该图像实际上已加载两次并转换为位图以便在屏幕上显示。所以实际上,你需要加倍你的内存大小。每次拍摄完整的图像时,我都会通过创建预览图像来解决这个问题。我会在处理真实图像时显示预览。如果用户想要缩放,我加载了完整的图像。大多数用户快速决定是否保留图像或丢弃不到一秒钟,因此这个预览节省了大量的处理时间。



或者像Sandeep说,创建该图像的缩略图并显示,如果您的应用程序可以处理它。



我看不到很多应用程序,你需要一个真正的高分辨率图像,除非你正在开发专业的照片软件(你不一定在.NET中做)或做某种医疗或工业成像,你需要放大或骨头的裂缝或桥梁的毛孔具体。即使在这种情况下,您也可以将该图像拆分为可以根据需要加载的扇区。



由于应用程序,您是否肯定与大文件绑定?



Ryan McBeth
I agree with Sandeep.

I wrote a camera driver for Windows CE once. Most of my experience with images comes from Windows CE / Mobile, so I can't fully speak for exactly what is going on in Win32, but I would assume that there are similarities.

That image is really getting loaded twice and being converted to a bitmap for display on screen. So in reality, you need to double your memory size. I got around this by creating a preview image every time I captured the full image. I would display the preview while the real image processed. If the user wanted to zoom, I loaded the full image. Most users made a quick decision as to whether to keep the image or discard in less than a second, so this preview saved a lot of processing time.

Or, like Sandeep said, create a thumbnail of that image and display that, if your application can handle that.

I can't see many applications where you need a genuine high-resolution image, unless you are developing professional photo software (which you wouldn't necessarily be doing in .NET) or doing some kind of medical or industrial imaging where you need to zoom in or the cracks in a bone or the pores in a bridge's concrete. And even in that case, you can split that image up into sectors that you can load as needed.

Are you definitely tied to a large file because of the application?

Ryan McBeth


这篇关于Image.FromFile()抛出内存不足异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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