How to create BIG bitmaps with RenderTargetBitmap?
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: T开发者_C百科he final store target is a file, either a lossy .jpg or a losseless .png.
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.
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.
精彩评论