Problems when exporting diagrams


#1

Hi,
We’re experiencing problems when exporting some quite large diagrams to bitmaps with the GetBitmapFromCollection method. Specifically we get an “Invalid parameter” exception in the Bitmap constructor, so it seems to be related to the width and/or height parameters there. These diagrams have been subject to auto-layout, so they might be containing negative coordinates.
My guess is that it’s either caused by the diagram size or negative coordinates or a combination. (Everything works fine for smaller diagrams).
Any help or ideas on this would be greatly appreciated.
Regards,
Bent Ivar Helland, System Developer, TietoEnator


#2

Hmmm, maybe we ought to implement some limits within that method. For an alternative, try:
public Bitmap GetBitmap(GoDocument doc) {
RectangleF docBounds = doc.ComputeBounds();
Size bmsize = new Size((int)docBounds.Width, (int)docBounds.Height);
float sc = Math.Min(2048f/bmsize.Width, 2048f/bmsize.Height);
if (sc > 1) sc = 1;
bmsize.Width=(int)(scbmsize.Width);
bmsize.Height=(int)(sc
bmsize.Height);
// you can customize how the Bitmap is created here:
Bitmap buf = new Bitmap(bmsize.Width, bmsize.Height, System.Drawing.Imaging.PixelFormat.Format16bppRgb555);
Graphics gbuf = Graphics.FromImage(buf);
GoView view = new GoView();
Color color = doc.PaperColor;
if (color == Color.Empty)
color = view.BackColor;
gbuf.FillRectangle(new SolidBrush(color), 0, 0, bmsize.Width, bmsize.Height);
PointF viewLoc = docBounds.Location;
gbuf.ScaleTransform(sc, sc);
gbuf.TranslateTransform(-viewLoc.X, -viewLoc.Y);
foreach (GoObject obj in doc) {
if (!obj.CanView())
continue;
obj.Paint(gbuf, view);
}
gbuf.Dispose();
return buf;
}