←Select platform

RenderRedirect Method

Summary

Render the content of the viewer to an external context.

Syntax

C#
VB
C++
public virtual void RenderRedirect( 
   Graphics graphics, 
   ImageViewerRenderRedirectOptions options, 
   LeadRect clipRectangle 
) 

Public Overridable Sub RenderRedirect( 
   ByVal graphics As System.Drawing.Graphics, 
   ByVal options As ImageViewerRenderRedirectOptions, 
   ByVal clipRectangle As LeadRect 
) 

public:  
   virtual void RenderRedirect( 
      System::Drawing::Graphics^ graphics, 
      ImageViewerRenderRedirectOptions^ options, 
      LeadRect^ clipRectangle 
   ) 

Parameters

graphics

Target device context to render the content of the viewer to.

options

Rendering options

clipRectangle

Clipping rectangle to use.

Remarks

This method can be used to render the content of the viewer to an external context. ImageViewerPanControl uses this method to show a smaller version of the viewer in a separate external control.

To take a "snapshot" of the viewer surface to perform such operations as screen capture or printing, use RenderRedirect passing it the target context (of the printer or a bitmap).

To perform live updates for operations such as pan window, subscribe to the RedirectRender event to get notified whenever the viewer content is changed. Then call RenderRedirect to render the content of the viewer into the target device.

During the render cycle, the value of IsRenderRedirected will be set to true if this particular rendering operation is targeting an external device other than the viewer itself. If you are performing custom rendering, you can check the value of this property to apply any modification needed.

Example

This example will mirror the content of the viewer into an external control with live updates whenever the viewer content changes.

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#
VB
using Leadtools; 
using Leadtools.Controls; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
using LeadtoolsExamples.Common; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
 
PictureBox control = new PictureBox(); 
control.Width = 400; 
control.Dock = DockStyle.Right; 
control.BringToFront(); 
_imageViewer.BringToFront(); 
 
bool renderView = false; 
 
control.DoubleClick += (sender, e) => 
{ 
   renderView = !renderView; 
   control.Invalidate(); 
}; 
 
control.Paint += (sender, e) => 
{ 
   Graphics graphics = e.Graphics; 
 
   int delta = 20; 
   LeadRect destRect = LeadRect.Create(delta, delta, control.ClientSize.Width - delta * 2, control.ClientSize.Height - delta * 2); 
   LeadRect clipRect = destRect; 
 
   ImageViewerRenderRedirectOptions options = new ImageViewerRenderRedirectOptions(); 
 
   ImageViewerItem item = null; 
   if (!renderView) 
      item = _imageViewer.Items[0]; 
 
   LeadRectD sourceRect; 
 
   if (item == null) 
      sourceRect = _imageViewer.GetViewBounds(true, false); 
   else 
   { 
      sourceRect = _imageViewer.GetItemViewBounds(item, ImageViewerItemPart.Image, false); 
      options.RenderBackgrounds = false; 
      options.RenderBorders = false; 
      options.RenderItemStates = false; 
      options.RenderShadows = false; 
      options.RenderText = false; 
   } 
 
   options.CreateTransform(_imageViewer, destRect, sourceRect, ControlSizeMode.FitAlways, ControlAlignment.Center, ControlAlignment.Center); 
   clipRect = options.Transform.TransformRect(sourceRect).ToLeadRect(); 
 
   _imageViewer.RenderRedirect(graphics, options, clipRect); 
 
   graphics.DrawRectangle(Pens.Black, destRect.X, destRect.Y, destRect.Width + 1, destRect.Height + 1); 
 
   // Now lets find out how much of the view is visible (something pan window would do) 
   LeadRectD rect; 
   if (item == null) 
      rect = _imageViewer.GetViewBounds(true, true); 
   else 
      rect = _imageViewer.GetItemViewBounds(item, ImageViewerItemPart.Image, true); 
 
   LeadPointD[] points = 
   { 
      LeadPointD.Create(rect.Left, rect.Top), 
      LeadPointD.Create(rect.Right, rect.Bottom) 
   }; 
 
   options.Transform.TransformPoints(points); 
 
   double xmin = points[0].X; 
   double ymin = points[0].Y; 
   double xmax = xmin; 
   double ymax = ymin; 
 
   for (int i = 1; i < points.Length; i++) 
   { 
      if (points[i].X < xmin) xmin = points[i].X; 
      if (points[i].X > xmax) xmax = points[i].X; 
      if (points[i].Y < ymin) ymin = points[i].Y; 
      if (points[i].Y > ymax) ymax = points[i].Y; 
   } 
 
   LeadRectD bounds = LeadRectD.FromLTRB(xmin, ymin, xmax, ymax); 
   RectangleF rc = new RectangleF((float)bounds.X, (float)bounds.Y, (float)bounds.Width, (float)bounds.Height); 
   graphics.DrawRectangle(Pens.Yellow, rc.X, rc.Y, rc.Width - 1, rc.Height - 1); 
}; 
 
_imageViewer.RedirectRender += (sender, e) => 
{ 
   control.Invalidate(); 
}; 

Imports Leadtools 
Imports Leadtools.Controls 
Imports Leadtools.Codecs 
Imports Leadtools.Drawing 
Imports Leadtools.ImageProcessing 
Imports Leadtools.ImageProcessing.Color 
Imports LeadtoolsControlsExamples.LeadtoolsExamples.Common 
 
Dim control As PictureBox = New PictureBox() 
control.Width = 400 
control.Dock = DockStyle.Right 
control.BringToFront() 
_imageViewer.BringToFront() 
 
Dim renderView As Boolean = False 
 
AddHandler control.DoubleClick, 
Sub(sender, e) 
   renderView = Not renderView 
   control.Invalidate() 
End Sub 
 
AddHandler control.Paint, 
Sub(sender, e) 
   Dim graphics As Graphics = e.Graphics 
 
   Dim delta As Integer = 20 
   Dim destRect As LeadRect = LeadRect.Create(delta, delta, control.ClientSize.Width - delta * 2, control.ClientSize.Height - delta * 2) 
   Dim clipRect As LeadRect = destRect 
 
   Dim options As ImageViewerRenderRedirectOptions = New ImageViewerRenderRedirectOptions() 
 
   Dim item As ImageViewerItem = Nothing 
   If (Not renderView) Then 
      item = _imageViewer.Items(0) 
   End If 
 
   Dim sourceRect As LeadRectD 
 
   If item Is Nothing Then 
      sourceRect = _imageViewer.GetViewBounds(True, False) 
   Else 
      sourceRect = _imageViewer.GetItemViewBounds(item, ImageViewerItemPart.Image, False) 
      options.RenderBackgrounds = False 
      options.RenderBorders = False 
      options.RenderItemStates = False 
      options.RenderShadows = False 
      options.RenderText = False 
   End If 
 
   options.CreateTransform(_imageViewer, destRect, sourceRect, ControlSizeMode.FitAlways, ControlAlignment.Center, ControlAlignment.Center) 
   clipRect = options.Transform.TransformRect(sourceRect).ToLeadRect() 
 
   _imageViewer.RenderRedirect(graphics, options, clipRect) 
 
   graphics.DrawRectangle(Pens.Black, destRect.X, destRect.Y, destRect.Width + 1, destRect.Height + 1) 
 
   ' Now lets find out how much of the view is visible (something pan window would do) 
   Dim rect As LeadRectD 
   If item Is Nothing Then 
      rect = _imageViewer.GetViewBounds(True, True) 
   Else 
      rect = _imageViewer.GetItemViewBounds(item, ImageViewerItemPart.Image, True) 
   End If 
 
   Dim points As LeadPointD() = {LeadPointD.Create(rect.Left, rect.Top), LeadPointD.Create(rect.Right, rect.Bottom)} 
 
   options.Transform.TransformPoints(points) 
 
   Dim xmin As Double = points(0).X 
   Dim ymin As Double = points(0).Y 
   Dim xmax As Double = xmin 
   Dim ymax As Double = ymin 
 
   Dim i As Integer = 1 
   Do While i < points.Length 
      If points(i).X < xmin Then 
         xmin = points(i).X 
      End If 
      If points(i).X > xmax Then 
         xmax = points(i).X 
      End If 
      If points(i).Y < ymin Then 
         ymin = points(i).Y 
      End If 
      If points(i).Y > ymax Then 
         ymax = points(i).Y 
      End If 
      i += 1 
   Loop 
 
   Dim bounds As LeadRectD = LeadRectD.FromLTRB(xmin, ymin, xmax, ymax) 
   Dim rc As RectangleF = New RectangleF(CSng(bounds.X), CSng(bounds.Y), CSng(bounds.Width), CSng(bounds.Height)) 
   graphics.DrawRectangle(Pens.Yellow, rc.X, rc.Y, rc.Width - 1, rc.Height - 1) 
End Sub 
 
AddHandler _imageViewer.RedirectRender, Sub(sender, e) control.Invalidate() 

Requirements

Target Platforms

Help Version 20.0.2018.6.20
Products | Support | Contact Us | Copyright Notices
© 1991-2018 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Controls Assembly