←Select platform

PostRender Event

Summary

Occurs after the view is rendered.

Syntax
C#
C++
public event EventHandler<ImageViewerRenderEventArgs> PostRender 
vb[VB Syntax] 
Public Event PostRender As EventHandler(Of Leadtools.Controls.ImageViewerRenderEventArgs) 
public:  
   event EventHandler<Leadtools::Controls::ImageViewerRenderEventArgs^>^ PostRender 
Remarks

For more information, refer to Image Viewer Rendering.

Example

This example will show how to customize the view rendering to draw extra shapes with and without transformation.

Start with the ImageViewer example, remove all the code inside the example function (search for the "// TODO: add example code here" comment) and insert the following code:

C#
using Leadtools; 
using Leadtools.Controls; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
 
 
public void ImageViewerPostRender_Example() 
{ 
   // Clear all the images already the viewer 
   _imageViewer.Items.Clear(); 
   // Use vertical view layout 
   _imageViewer.ViewLayout = new ImageViewerVerticalViewLayout(); 
   // Make sure the item size is larger than the image size (thumbnails mode) 
   _imageViewer.ItemSize = LeadSize.Create(200, 200); 
   _imageViewer.ItemPadding = new Padding(8, 8, 8, 20); 
   _imageViewer.ImageBorderThickness = 1; 
 
   // Add 4 items to the viewer 
   using (var codecs = new RasterCodecs()) 
   { 
      for (var page = 1; page <= 4; page++) 
      { 
         var item = new ImageViewerItem(); 
         var fileName = Path.Combine(LEAD_VARS.ImagesDir, string.Format("ocr{0}.tif", page)); 
 
         // Create a thumbnail from the image 
         using (var image = codecs.Load(fileName, page)) 
         { 
            item.Image = image.CreateThumbnail(180, 180, 24, RasterViewPerspective.TopLeft, RasterSizeFlags.Resample); 
         } 
 
         item.Text = string.Format("Item {0}", page - 1); 
         _imageViewer.Items.Add(item); 
      } 
   } 
 
   // Render on the view 
   _imageViewer.PostRender += (sender, e) => 
   { 
      // Rendering the whole view 
      var graphics = e.PaintEventArgs.Graphics; 
 
      // Blue ellipse at fixed position. This will stay the same and will not scroll or zoom 
      using (var brush = new SolidBrush(Color.FromArgb(128, Color.Blue))) 
         graphics.FillEllipse(brush, new Rectangle(0, 0, 100, 100)); 
 
      // Red ellipse at relative position, this will scroll and zoom with the view 
      var gstate = graphics.Save(); 
 
      var transform = _imageViewer.ViewTransform; 
      using (var matrix = new System.Drawing.Drawing2D.Matrix( 
         (float)transform.M11, (float)transform.M12, (float)transform.M21, (float)transform.M22, 
         (float)transform.OffsetX, (float)transform.OffsetY)) 
         graphics.MultiplyTransform(matrix); 
 
      graphics.FillEllipse(Brushes.Red, new Rectangle(0, 0, 100, 100)); 
 
      graphics.Restore(gstate); 
   }; 
 
   // Render on each item 
   _imageViewer.PostRenderItem += (sender, e) => 
   { 
      var item = e.Item; 
 
      var graphics = e.PaintEventArgs.Graphics; 
 
      var gstate = graphics.Save(); 
 
      // Get the bounding rectangle for the image 
      var bounds = LeadRectD.Create(0, 0, item.Image.ImageWidth, item.Image.ImageHeight); 
 
      // Add the image transform to the graphics 
      var transform = _imageViewer.GetItemImageTransform(item); 
      using (var matrix = new System.Drawing.Drawing2D.Matrix( 
         (float)transform.M11, (float)transform.M12, (float)transform.M21, (float)transform.M22, 
         (float)transform.OffsetX, (float)transform.OffsetY)) 
         graphics.MultiplyTransform(matrix); 
 
      // Red hilight on top of each item image 
      using (var brush = new SolidBrush(Color.FromArgb(128, Color.Red))) 
         graphics.FillRectangle(brush, (float)bounds.X, (float)bounds.Y, (float)bounds.Width, (float)bounds.Height); 
 
      graphics.Restore(gstate); 
   }; 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Event Data
ParameterTypeDescription
senderobjectThe source of the event.
eImageViewerRenderEventArgsThe event data.
Requirements

Target Platforms

Help Version 22.0.2022.4.4
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2022 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Controls Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2022 LEAD Technologies, Inc. All Rights Reserved.