←Select platform

CreateTransform Method

Summary

Helper method to create the transformation matrix used to redirect the rendering of the ImageViewer.

Syntax
C#
C++/CLI

Parameters

imageViewer

The image viewer instance that will be used as the source of RenderRedirect. This value

cannot be null.

destinationRect

Destination rectangle to use. For example, the client area of the external control.

sourceRect

The source rectangle into the current view of imageViewer. Pass Empty to render

the whole view.

sizeMode

Controls how the source rectangle is positioned and scaled inside the destination rectangle.

horizontalAlignment

Controls how the source rectangle is aligned horizontally inside the destination rectangle.

verticalAlignment

Controls how the source rectangle is aligned vertically inside the destination rectangle.

Remarks

This method will set the transformation matrix into Transform.

Use this method CreateTransform can be used to easily create a transformation matrix for common scenarios such as rendering a thumbnail of the content of the viewer.

For more information, refer to Image Viewer Rendering.

Example
C#
using Leadtools; 
using Leadtools.Controls; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
 
 
public void TestRedirectRender() 
{ 
   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(); 
   }; 
} 
Requirements

Target Platforms

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

Leadtools.Controls Assembly

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