HOWTO: Burn annotations with the WebAnnotationViewer


Legacy Controls NOTICE

This article references our legacy Web Forms Web Viewing controls (WebImageViewer, WebAnnotationViewer, WebThumbnailViewer). It is preserved for archival purposes, but support strongly recommends using our modern HTML5 web controls: WebDocumentViewer, WebDocumentThumbnailer instead)

INFO: WebDocumentViewer Whitepaper - Getting Started With Web Viewing

Main Article Content

This code sample shows how you can burn all of the annotations contained in the WebAnnotationViewer's LayerCollection onto an AtalaImage.

C#

AtalaImage img = BurnAnnotations(this.WebAnnotationViewer1.Annotations.Layers, this.WebAnnotationViewer1.Image);

// Burns the given LayerCollection onto the given image if possible
// otherwise, burns the LayerCollection onto a copy of the given image
private AtalaImage BurnAnnotations(LayerCollection layers, AtalaImage image)
{
   AtalaImage burn = image;

   if (burn != null)
   {
      // Can't render annotations on indexed PixelFormats
      if (burn.PixelFormat != PixelFormat.Pixel24bppBgr && burn.PixelFormat != PixelFormat.Pixel32bppBgra)
      {
         ChangePixelFormatCommand cmd = new ChangePixelFormatCommand(PixelFormat.Pixel32bppBgra);
         burn = cmd.Apply(image).Image;
      }

      RenderEnvironment re = new RenderEnvironment(RenderDevice.Display, burn.GetGraphics(), new PointF(1, 1), AnnotationUnit.Pixel, null, new PointF((float)image.Resolution.X, (float)image.Resolution.Y));

      foreach (LayerAnnotation layer in layers)
      {
         foreach (AnnotationUI ann in layer.Items)
         {
            IAnnotationRenderer renderer = AnnotationRenderers.Get(ann.Data.GetType());
            renderer.RenderAnnotation(ann.Data, re);
         }
      }
   }

   return burn;
}

Original Article:
Q10164 - HOWTO: Burning annotations with the WebAnnotationViewer