如何使用 RenderTargetBitmap 创建大位图?
我需要使用 RenderTargetBitmap 将大视觉存储为位图图像,而不会出现内存不足异常。实现这一目标的最佳方法是什么?
我可以毫无问题地存储屏幕大小的视觉对象(比如说 1920x1200 像素),但是当视觉对象非常大(20000x20000 像素)时就会发生崩溃。
也许不使用 RenderTargetBitmap?还有其他选择吗?
注意:最终存储目标是一个文件,可以是有损 .jpg 或无损 .png。
I need to store a big Visual as bitmap image using RenderTargetBitmap without obtaining an Out-Of-Memory exception. What is the best way to achieve this?
I have no problem storing a Visual the size of the screen (let say 1920x1200 pixels), but the crash occurs when the visual is very big (20000x20000 pixels).
Maybe not using RenderTargetBitmap? are there alternatives?
NOTE: The final store target is a file, either a lossy .jpg or a losseless .png.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
20000 x 20000 像素 = 400000000 像素。每个像素乘以 4 字节 = 1.5 Gb(未压缩数据),
这太大了。
我会创建多个图像并缝合它们,或者使用更小的图像并将它们用作图块。
20000 x 20000 pixels = 400000000 pixels. Times 4 bytes per pixel = 1.5 Gb (uncompressed data)
That is simply too big.
I'd create multiple images and stitch them or use even smaller images and use them as tiles.
您是否考虑过创建 XPS 文档? 将 WPF (XAML) 控件转换为 XPS 文档
基本上,您可以将视觉元素转储到 Microsoft 版本的 PDF 中 - 标准查看器现在很常见,并且内置在 Win 7 中。
XPS 文档的优点是它是基于矢量的,因此它只存储绘图指令。 (您可以看到,如果将 XPS 文档重命名为 ZIP 并将其解压缩,效果如何。)
如果您的视觉效果中已经嵌入了大型光栅类型图像,这可能不起作用,但可以尝试一下。
Have you looked at creating an XPS document? Convert WPF (XAML) Control to XPS Document
Basically, you can take a visual element and dump it out into Microsoft's version of a PDF - a standard viewer is pretty commonly installed on boxes these days, and comes built-in in Win 7.
The advantage of an XPS document is that it's vector based so it's just storing drawing instructions. (You can see how if you rename an XPS doc to ZIP and unzip it.)
If you have large raster type images embedded in your visuals already, this may not work, but something to try.