GoView::CopyToClipboard

I have a GoDiagram application that creates organization charts. I use the GoView::CopyToClipboard method and override the CreateDataObject method, which uses the GetBitmapFromCollection method. I have noticed that once the org chart view gets large, the bitmap placed onto the clipboard gets fuzzy. Is there some upper limit on the size of the bitmaps such that, beyond that limit, the bitmap is “shrunk to fit”, so to speak? For relatively smaller charts, the bitmap is very clear, just like what is displayed in my view window.

Yes, some years ago we noticed a problem with GDI+ exceptions when bitmaps got too big, typically because users selected a collection of objects spread over a “large” area.
So we added an overload to GoView.GetBitmapFromCollection that took a scale argument, and changed the GetBitmapFromCollection used by CreateDataObject (and other similar places) to limit the bitmap to about 2000x2000 pixels.
You can get around this particular limit by calling the most general overload of GetBitmapFromCollection. Perhaps:
protected override DataObject CreateDataObject(IGoCollection coll, GoDocument clipdoc) {
DataObject dataobj = new DataObject();
dataobj.SetData(clipdoc.DataFormat, clipdoc);
Bitmap bm = GetBitmapFromCollection(clipdoc, GoDocument.ComputeBounds(coll), 1, true);
dataobj.SetData(DataFormats.Bitmap, true, bm);
return dataobj;
}

Thanks Walter. A couple of follow-ups:

  1. The ComputeBounds method actually takes 2 parms, the second parm being the GoView. So, I just added “this” to the parm list.
  2. I am getting Paste errors when I try to paste the bitmap into Visio and MSPaint. The error is “Unable to retrieve the bitmap data from the clipboard.”
    Any thoughts?
  1. Thanks. That’s what I get for just typing like a monkey.
  2. Selecting some objects in Demo1, ^C, and then ^V works fine in Paint for me. I don’t understand why PasteSpecial doesn’t work in Visio. PasteSpecial works fine for me in Word and Powerpoint and Excel.

Thanks Walter. Your suggestion above works great. However, there must be some upper limit on the size of bitmaps that can be pasted from the clipboard. On my large documents, when I receive the Paste error, if I back down the DocScale from 1.0 to 0.9 and recopy to the clipboard, the Paste works. You wouldn’t happen to know of such a limit would you? That way, I could handle it programatically.
Thanks for the help.

Hey, if I knew, I wouldn’t have hardcoded 2000x2000 either. You’ll have to ask Microsoft and their GDI+ group. I was just guessing that a 16 megabyte bitmap was a reasonable limit that would satisfy most needs (i.e. covering a typical monitor) while minimizing the chances for running out of memory. More sophisticated solutions are possible too, but that is beyond the scope of this post.
Consider also that the limit on what the user can Paste might also be dependent on the receiving application, not just GDI+.

Got it. Thanks again, Walter.