Exporting to bitmap creates unwanted border/margin


I have been struggling a bit with the method


More specifically on how to properly export an image given the document objects bounds.
The method itself is working fine and the expected image is created … but … with a margin that I can’t figure out how to remove.

It seems like somewhere in the code there is something that adds spacing.

That basiclly visualizes the result I want to get, and what I do get right now. The first picture to the left is having a slight margin and the one to the right is what I want to get with no margin outside / around the object(s).

a couple of things…

GoDocument.Bounds grows as you add & move objects, but it doesn’t shrink by itself. You have to force it by:

doc.Bounds = doc.ComputeBounds()

second… GetBitmapFromCollection has several signatures. Look at the ones with more parameters for more control over the export.

I guess I should have mentioned that I did document.ComputeBounds() already and it’s with that the borders comes.

It leads me to believe that either the painting, or the compute bounds is returning “salted” bounds with the margin.

ComputeBounds does include the ExpandPaintBounds for each object, so you are picking up a little extra there, depending on the objects. I suspect that’s what you’re seeing.

You could iterate the objects and do your own Bounds computation if you want exact bounds.

Can I set the ExpandPaintBounds on an object to be zero? (That would probably solve my problem)

not without overriding the method on all of the objects… and you wouldn’t want to do that.

The reason for having ExpandPaintBounds is to cover things like shadows.
Even if there’s no shadow, you would still need to be concerned about anti-aliasing and pixel positioning.
That computation covers the document’s area, but doesn’t account for selection handles and such, which belong to the GoView.
Finally, we originally didn’t have those extra margins, and people complained, even when none of the just-mentioned reasons applied.

So I suggest you do what Jake suggested – either calculate the bounds you want in your own manner, or just use a value somewhat smaller than that returned by ComputeBounds.

Thank you for the suggestions. Will try them out on monday! :)