处理大型位图(最大 3GB) [英] Processing on large bitmaps (up to 3GB)

查看:41
本文介绍了处理大型位图(最大 3GB)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一些大学项目,但遇到了内存问题.我加载了一个位图,它在硬盘上占用了大约 1.5GB 的空间,代码如下:

I'm working on some university project and got stuck with memory issue. I load a bitmap which takes about 1,5GB on HDD with code below:

Bitmap bmp = new Bitmap(pathToFile); 

问题是新创建的 Bitmap 对象使用了大约 3.5GB 的 RAM,这是我无法理解的(这真是大包装:E).我需要访问像素数组,Bitmap 类的使用真的很有帮助(我稍后使用 LockBits() 方法,并处理每个字节的数组字节)但在这种情况下它完全是阻塞器.所以这是我的问题:

The issue is that the newly created Bitmap object uses about 3,5GB of RAM which is something I can't understand (that's really BIG wrapper :E). I need to get to the pixel array, and the use of Bitmap class is really helpful (I use LockBits() method later, and process the array byte per byte) but in this case it's total blocker. So here is my question:

有没有什么简单的方法可以在不借出额外 2gb 的情况下提取像素阵列?

Is there any easy way to extract the pixel array without lending additional 2gb?

我使用 c# 只是为了提取所需的数组,稍后在 c++ 中处理 - 也许我可以在 c++ 中提取所有需要的数据(但这里出现转换问题 - 我专注于 24bgr 格式)?

I'm using c# just to extract the needed array, which is later processed in c++ - maybe I can extract all needed data in c++ (but conversion issue appears here - I'm concentrating on 24bgr format)?

PS:我需要将整个位图保留在内存中,因此将其拆分为多个部分不是解决方案.

PS: I need to keep the whole bitmap in memory so splitting it into parts is no solution.

PS2:只是澄清一些问题:我知道文件扩展名和文件格式之间的区别.加载的文件是未压缩的位图,每像素 3 个字节,大小为 ~1.42GB(16k x 32k 像素),那么为什么 Bitmap 对象要大两倍以上?没有发生任何解压问题和转换为其他格式的问题.

PS2: Just to clarify some issues: I know the difference between file extension and file format. The loaded file is uncompressed bitmap 3 bytes per pixel of size ~1.42GB (16k x 32k pixels), so why Bitmap object is more than two times bigger? Any decompressing issues and converting into other format aren't taking place.

推荐答案

考虑使用内存映射文件来访问您的巨大数据:).可以在此处找到专注于您需要的示例:http:///visualstudiomagazine.com/articles/2010/06/23/memory-mapped-files.aspx它在托管代码中,但您也可以从等效的本机代码中使用它.

Consider using Memory Mapped Files to access your HUGE data :). An example focused on what you need can be found here: http://visualstudiomagazine.com/articles/2010/06/23/memory-mapped-files.aspx It's in managed code but you might as well use it from equivalent native code.

如果您需要更多详细信息,请告诉我.

Let me know if you need more details.

这篇关于处理大型位图(最大 3GB)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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