Exporting Images

I am trying to export an image that is larger than the default GoView used to edit the document. I followed the instructions on another thread for creating a temporary view when rendering the image:
</FONT> public Bitmap <SPAN =highlight>GetBitmap</SPAN>(GoDocument doc) {<BR> RectangleF docBounds = doc.ComputeBounds();<BR> Size bmsize = new Size((int)docBounds.Width, (int)docBounds.Height);<BR> float sc = Math.Min(2048f/bmsize.Width, 2048f/bmsize.Height);<BR> if (sc > 1) sc = 1;<BR> bmsize.Width=(int)(sc*bmsize.Width);<BR> bmsize.Height=(int)(sc*bmsize.Height); // you can customize how the Bitmap is created here:<BR> Bitmap buf = new Bitmap(bmsize.Width, bmsize.Height, System.Drawing.Imaging.PixelFormat.Format16bppRgb555); Graphics gbuf = Graphics.FromImage(buf); GoView view = new GoView();<BR> Color color = doc.PaperColor;<BR> if (color == Color.Empty)<BR> color = view.BackColor;<BR> gbuf.FillRectangle(new SolidBrush(color), 0, 0, bmsize.Width, bmsize.Height); PointF viewLoc = docBounds.Location;<BR> gbuf.ScaleTransform(sc, sc);<BR> gbuf.TranslateTransform(-viewLoc.X, -viewLoc.Y); foreach (GoObject obj in doc) {<BR> if (!obj.CanView())<BR> continue;<BR> obj.Paint(gbuf, view);<BR> } gbuf.Dispose();<BR> return buf;<BR>}
This fixed the size problem, but now my rendered images suffer from poor quality. The lines are not smoothed and the fonts are not antialiased. I tried adding these lines after the temporary view is created:<FONT size=2> view.TextRenderingHint = Drawing.Text.TextRenderingHint.ClearTypeGridFit view.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic view.SmoothingMode = Drawing2D.SmoothingMode.HighQuality view.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality view.CompositingQuality = Drawing2D.CompositingQuality.AssumeLinear
But it doesn’t fix the problem. Any ideas?

Have you tried using the GoView.GetBitmapFromCollection method that takes four arguments, including a scale? This will create an arbitrarily large Bitmap, but you need to be careful that it isn’t too big, since GDI+ and your machine has limits on how large a bitmap it can create.
Something like:
GoDocument doc = goView1.Document;
goView1.GetBitmapFromCollection(doc, doc.ComputeBounds(doc, goView1), 1.0f, false);
Of course if you want to run this code in a different thread, you’ll need to create a separate GoView that uses the original GoDocument.

And I end up with a completely black bitmap. It looks like the bounds of the bitmap are correct, though.

OK, I just tried this:
GoDocument doc = goView1.Document;
Bitmap viewbm = goView1.GetBitmapFromCollection(doc, doc.ComputeBounds(), 1.0f, false);
Stream doc1outf = File.OpenWrite(@“doc.png”);
viewbm.Save(doc1outf, ImageFormat.Png);
It worked fine. Also if I create a GoImage using that Bitmap, it appears fine as a (big) object in my GoView/GoDocument.
Hmmm, I haven’t tried running this in a separate thread, though.
What are your expected bitmap bounds? Are you running the above code in a different thread from your main GoView’s thread?

My application is single threaded. It is a vb.net application. My code looks like this: <FONT color=#0000ff size=2>Dim</FONT><FONT size=2> doc </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> GoDocument = </FONT><FONT color=#0000ff size=2>Me</FONT><FONT size=2>.goView.Document<BR></FONT><FONT size=2>_bmpCrop = </FONT><FONT color=#0000ff size=2>Me</FONT><FONT size=2>.goView.GetBitmapFromCollection(doc, GoDocument.ComputeBounds(doc, </FONT><FONT color=#0000ff size=2>Me</FONT><FONT size=2>.goView), 1.0F, </FONT><FONT color=#0000ff size=2>False</FONT><FONT size=2>)<BR>_bmpCrop.Save(Application.StartupPath & "\Temp\Graph.jpg", ImageFormat.Jpeg)
Note my call to ComputeBounds(). I don’t normally use VB but I got an error when I tried Me.goView.ComputeBounds(), my guess is that VB.Net will not call static function on an instantiation. Calling it from the function’s namespace seems to work, and the output size seems correct. Unfortunately, the result is a black image.

Hmmm. One difference is that my code uses a Stream instead of writing the disk file directly. I don’t know why that would make a difference, but…
Another difference is the ImageFormat. Again, I wouldn’t think that would make a difference, but…
How many objects are in the document that is being rendered? What is the size of the JPG image? Have you checked that that file really has been re-written each time, and is actually closed?

Hmmm. One difference is that my code uses a Stream instead of writing the disk file directly. I don’t know why that would make a difference, but…
Another difference is the ImageFormat. Again, I wouldn’t think that would make a difference, but…[/quote] That image format works fine when writing a bitmap created by .GetBitmap().

Around 10 GoObjects. The image is around 400x200px. Yes the file is definately being rewriten. I’ve deleted the file just to make sure.
Please help! I needed this feature to be complete yesturday!

Maybe the reason you are seeing a lot of black is that there’s no paper color and JPEG doesn’t support transparency. Try passing “true” as the last argument instead.
However, that wouldn’t explain why your image was completely black. Are you sure there isn’t anything visible in your image? Or are all of your objects only black? Can you see anything if you specify various colors in your objects?

Setting Paper = True fixed it. Thanks

I seem to be having a very similar problem however :

bmp = view.GetBitmapFromCollection (doc, doc.ComputeBounds (), 1.0F, true);

when saved both as jpg or png the imagas are showing the background as transparent i.e for png and black for jpg. I tried setting the PaperColor of the document prior to the call but this made no difference along with changing the value of paper in GetBitmapFromCollection.

I am using

When the “paper” argument to GetBitmapFromCollection is true, it calls GoView.PaintPaperColor. If the GoView.SheetStyle != None, that won’t use the GoDocument.PaperColor but the GoView.BackColor. That’s because when there is a GoView.Sheet, the sheet is assumed to be filled (since the sheet is just a GoObject), and the rest of the Control just gets the standard background color for the Control.

Resolved by assigning the document to a temporary view:

GoView tempview = new GoView(yourDocument);
Bitmap docbmp = tempview.<span =“highlight”>GetBitmapFromCollection(tempview.Document);

Unfortunately dont have the time to look into more - developers have heavily overriden the existing go classes.