Error processing SSI file
(Leadtools.Controls)

Show in webframe

PostRender Event




Occurs after the view is rendered.
Syntax
Event Data

The event handler receives an argument of type ImageViewerRenderEventArgs containing data related to this event. The following ImageViewerRenderEventArgs properties provide information specific to this event.

PropertyDescription
Context Current graphics context associated with this object.
Error Error that might have occurred during rendering.
Item Item to render
PaintEventArgs Native paint event arguments associated with this object
Part Item part to render
Remarks

For more information, refer to Image Viewer Rendering.

ImageViewerRenderEventArgs
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:

Copy Code  
Imports Leadtools
Imports Leadtools.Controls
Imports Leadtools.Codecs
Imports Leadtools.Drawing
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Color

' 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 codecs As New RasterCodecs()
   For page As Integer = 1 To 4
      Dim item As New ImageViewerItem()
      Dim fileName As String = Path.Combine(ImagesPath.Path, String.Format("ocr{0}.tif", page))

      ' Create a thumbnail from the image
      Using image As RasterImage = codecs.Load(fileName, page)
         item.Image = image.CreateThumbnail(180, 180, 24, RasterViewPerspective.TopLeft, RasterSizeFlags.Resample)
      End Using

      item.Text = String.Format("Item {0}", page - 1)
      _imageViewer.Items.Add(item)
   Next page
End Using

' Render on the view
AddHandler _imageViewer.PostRender,
Sub(sender, e)
   ' Rendering the whole view
   Dim graphics As Graphics = e.PaintEventArgs.Graphics

   ' Blue ellipse at fixed position. This will stay the same and will not scroll or zoom
   Using brush As New SolidBrush(Color.FromArgb(128, Color.Blue))
      graphics.FillEllipse(brush, New Rectangle(0, 0, 100, 100))
   End Using

   ' Red ellipse at relative position, this will scroll and zoom with the view
   Dim gstate As System.Drawing.Drawing2D.GraphicsState = graphics.Save()

   Dim transform As LeadMatrix = _imageViewer.ViewTransform
   Using matrix As New System.Drawing.Drawing2D.Matrix(CSng(transform.M11), CSng(transform.M12), CSng(transform.M21), _
                                                       CSng(transform.M22), CSng(transform.OffsetX), CSng(transform.OffsetY))
      graphics.MultiplyTransform(matrix)
   End Using

   graphics.FillEllipse(Brushes.Red, New Rectangle(0, 0, 100, 100))

   graphics.Restore(gstate)
End Sub

' Render on each item
AddHandler _imageViewer.PostRenderItem,
Sub(sender, e)
   Dim item As ImageViewerItem = e.Item

   Dim graphics As Graphics = e.PaintEventArgs.Graphics

   Dim gstate As System.Drawing.Drawing2D.GraphicsState = graphics.Save()

   ' Get the bounding rectangle for the image
   Dim bounds As LeadRectD = LeadRectD.Create(0, 0, item.Image.ImageWidth, item.Image.ImageHeight)

   ' Add the image transform to the graphics
   Dim transform As LeadMatrix = _imageViewer.GetItemImageTransform(item)
   Using matrix As New System.Drawing.Drawing2D.Matrix(CSng(transform.M11), CSng(transform.M12), CSng(transform.M21), _
                                                       CSng(transform.M22), CSng(transform.OffsetX), CSng(transform.OffsetY))
      graphics.MultiplyTransform(matrix)
   End Using

   ' Red hilight on top of each item image
   Using brush As New SolidBrush(Color.FromArgb(128, Color.Red))
      graphics.FillRectangle(brush, CSng(bounds.X), CSng(bounds.Y), CSng(bounds.Width), CSng(bounds.Height))
   End Using

   graphics.Restore(gstate)
using Leadtools;
using Leadtools.Controls;
using Leadtools.Codecs;
using Leadtools.Drawing;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Color;

// 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(ImagesPath.Path, 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);
};
Requirements

Target Platforms

See Also

Reference

ImageViewer Class
ImageViewer Members

Error processing SSI file