I have to save my FrameworkElement as very large raster image. For now I use the RenderTargetBitmap class and a BitmapEncoder, in this way:
RenderTargetBitmap bmp = new RenderTargetBitmap(ElementWidth, ElementHeight,
90, 96, PixelFormats.Default);
bmp.Render(MyElement); // OutOfMemoryException here
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bmp));
using (var stream = File.Create(filePath))
{ encoder.Save(stream); }
Where ElementWidth and ElementHeight are large numbers (about 10000x6000). But with this solution there's a OutOfMemoryException when i try to Render my element.
There are other ways to do what I need (without causing an OutOfMemoryException)? Thanks.
In this case, you're going to have to render the FrameworkElement in tiles. The easiest way to do this would be to set the Clip property to the position/size of the tile you want to render and then use an instance of a tile-sized RenderTargetBitmap to get that piece on disk. Now you can either
Of course, I don't know if option 2 is of any help because even if you do write the huge output file - how will anyone load it? :)
Hope this helps!