BitmapData 创建时分配大量内存

发布于 2025-01-02 02:46:06 字数 331 浏览 1 评论 0原文

我有一个处理高分辨率图像(大约 100+ 兆像素)的应用程序,但我遇到了一些内存问题。创建 BitmapData 对象时,它会分配内存来存储该图像。问题是,我已经有一个包含该图像像素的 ByteArray(大约有 400+ MB),因此当创建 BitmapData 时,它会分配内存来存储与 ByteArray 上相同的数据。

创建后,我可以将 ByteArray 中的像素设置为 BitmapData 并释放 ByteArray。但这种内存峰值有时会导致运行时引发异常,告知系统内存不足。

有没有办法告诉 BitmapData 使用我自己的 ByteArray?或者有任何其他解决方案,我不必使用我需要的双倍内存?

I have an application which manipulates high resolution images (something around 100+ megapixels), and I'm having some memory issues. When the BitmapData object is created, it allocates memory to store this image. The problem, is that I already have a ByteArray with this image's pixels (which have something around 400+ MB), so when the BitmapData is created, it allocates memory to store the same data that I have on the ByteArray.

After its creation, I can set the pixels from the ByteArray to the BitmapData and free the ByteArray. But this memory peak is, sometimes, causing the runtime to raise an exception, telling that the system is out of memory.

Is there any way to tell the BitmapData to use my own ByteArray? Or any other solution that I don't have to use double the memory that I need?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰火雁神 2025-01-09 02:46:06

如果有人需要这个,这就是我所做的:

我从套接字获取包含图像像素的 ByteArray。我从套接字中读取这些像素的微小部分,因此我没有等待从套接字加载整个图像,而是将这些小部分直接放入 BitmapData 中。这可以防止应用程序分配我实际需要的双倍内存。

In case anyone needs this, here's what I did:

I get the ByteArray, which contains the pixels of the image, from a socket. I read these pixels from the sockets in tiny parts, so I, instead of waiting for the whole image to be loaded from the socket, I put these small parts directly into the BitmapData. This prevents the application to allocate double the memory I actually need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文