I have an implementation to export a diagram to a png file:
List existingParts = new List();
Rect bounds = this.Diagram.Panel.ComputeBounds(existingParts);
if (bounds != Rect.Empty)
bounds = DefaultLayoutFactory.SetDefaultExtraPageMargin(bounds);
double w = bounds.Width;
double h = bounds.Height;
double s = 1.0;
if (w > 65536)
s = 65536/ w;
if (h > 65536)
s = Math.Min(s, 65536/ h);
w = Math.Ceiling(ws);
h = Math.Ceiling(hs);
BitmapSource bmp = this.Diagram.Panel.MakeBitmap(new Size(w, h), 96, new Point(bounds.X, bounds.Y), s);
PngBitmapEncoder png = new PngBitmapEncoder();
using (Stream stream = File.Create(filename))
If the diagram is very large (about height: 70000 and width: 90000) there I got a memory out of range exception. (BitmapSource bmp = this.Diagram.Panel.MakeBitmap…)
I know, that I shall reduce the 65536 “scale down” limit. I just play around with this value, because I want to avoid a reduction of bitmap export quality.
Is there any workaround, for example directly creating a PNG file (without bitmapsource) or rendering parts of the bitmap, encode it as png and stick these parts finaly together?
PNG is a lossless compressed image format. Even though the result is a relatively small image file, the source needs to be an uncompressed bitmap of some sort. Chances are that the 65536x65536 pixel is at least 3 and probably 4 bytes per pixel means the image is 3GB or 4GB in memory.
As you suggest, you could render a bunch of more reasonably sized tiles as separate bitmaps and then separate PNG files. But whatever tool you use to stitch them together into a single image would have the same problem.