slow to update the screen for metafile picturebase objects

Mar 1, 2013 at 1:01 PM
Hi,

for the public override void Draw(Graphics graphics) {} of Picturebase, it gets VERY SLOW if you have a lot of picturebase objects (more than 10) on the diagram.
it is constantly calling the function GdiHelpers.DrawImage: (see below)

if (image != null && image.Image is Metafile) {
            GdiHelpers.DrawImage(graphics, image.Image, imageAttribs, imageLayout, imageBounds, imageBounds, Geometry.TenthsOfDegreeToDegrees(Angle), Center);
for the ONPAINT, of the diagram, you are redrawing every shape, and everyshape is constantly recaling using GdiHelpers.DrawImage. Is there a way we can optimize this to scale the image ONLY once after it is loaded? or is there a way we can make the onpaint of the diagram not redraw all shapes constantly??

please help.
Coordinator
Mar 5, 2013 at 7:36 AM
First of all, only the shapes are redrawn that intersect with the clipping region (the region wich was invalidated). When simply moving a shape from A to B, it is likely that not all shapes are redrawn. Only when scrolling or zooming out, the whole display component is redrawn.

Regarding your question:
You cannot buffer Metafile images because these files consist of calls to GDI draw functions. That's the trick of vector graphics: They are drawn 'on the fly' and therefore, they cannot be buffered.
If you run into serious performance issues, try to
  • Use EMF graphics in EMF+ format. EMF+ graphics are drawn using the newer GDI+ function set instead of the old GDI function set which results (sometimes) im better performance.
  • Use EMF graphics with less details
  • use bitmap images (these are drawn with texture brushes that are buffered) or
  • compose your shapes of simple shapes (aggregate shapes).
    See sample diagram "Railway Network": The houses are shapes composed from other shapes and stored as template.
  • implement your own shapes
    The last option is the most difficult option but also the option with the biggest performance gain.
You could perhaps try to create some kind of 'buffered Vector Graphics' shape by drawing the contents of the meta file into a bitmap image which is used for rendering.
Advantage:
You only need to redraw the metafile when resizing the shape.
Disadvantage:
Because the shape does not know anything about zoom levels etc., the main advantage of vector graphics has to be sacrificed: When zooming in, the buffered bitmap image (which is drawn) gets chunky instead of staying sharp.