Occurs after the view is rendered.
public event EventHandler<Leadtools.Controls.ImageViewerRenderEventArgs> PostRender
Public Event PostRender As EventHandler(Of Leadtools.Controls.ImageViewerRenderEventArgs)
public:
event EventHandler<Leadtools::Controls::ImageViewerRenderEventArgs^>^ PostRender
For more information, refer to Image Viewer Rendering.
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:
using Leadtools;
using Leadtools.Controls;
using Leadtools.Codecs;
using Leadtools.Drawing;
using LeadtoolsExamples.Common;
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);
};
Imports Leadtools
Imports Leadtools.Controls
Imports Leadtools.Codecs
Imports Leadtools.Drawing
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Color
Imports LeadtoolsControlsExamples.LeadtoolsExamples.Common
' 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)
Parameter | Type | Description |
---|---|---|
sender | object | The source of the event. |
e | ImageViewerRenderEventArgs | The event data. |
Products |
Support |
Feedback: PostRender Event (ImageViewer) - Leadtools.Controls |
Introduction |
Help Version 19.0.2017.6.20
|
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.