Draws and pans a spy glass on the viewer.
public class ImageViewerSpyGlassInteractiveMode : ImageViewerInteractiveMode
@interface LTImageViewerSpyGlassInteractiveMode : LTImageViewerInteractiveMode
public ref class ImageViewerSpyGlassInteractiveMode : ImageViewerInteractiveMode
ImageViewerSpyGlassInteractiveMode derives from ImageViewerInteractiveMode and subscribes to the following events of the InteractiveService:
The mode will set InteractiveEventArgs.IsHandled to true under the normal conditions for these events.
The ImageViewerSpyGlassInteractiveMode interactive mode does not perform any action on the viewer (besides drawing the the spy glass). It is up to the user to implement any custom operation required, (for example, to implement a magnify glass). The ImageViewerMagnifyGlassInteractiveMode derives from the ImageViewerSpyGlassInteractiveMode and overrides the OnDrawImage method to draw a magnified version of the area under the spy glass.
The ImageViewerSpyGlassInteractiveMode also supports redirecting the output to an external control instead of the viewer surface. For an example, refer to RedirectControl.
For more information, refer to Image Viewer Interactive Modes.
This example will use ImageViewerSpyGlassInteractiveMode to show an inverted portion of the image under the mouse.
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 Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Color;
public ImageViewerForm _form = new ImageViewerForm();
public ImageViewer _imageViewer;
public void ImageViewerSpyGlassInteractiveModeExample()
{
// Get the ImageViewer control from the form
_imageViewer = _form.ImageViewer;
// Load an image
using (var codecs = new RasterCodecs())
_imageViewer.Image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "image1.cmp"));
// Create the spyglass interactive mode
ImageViewerSpyGlassInteractiveMode spyGlass = new ImageViewerSpyGlassInteractiveMode();
spyGlass.AutoItemMode = ImageViewerAutoItemMode.AutoSet;
spyGlass.BackgroundBrush = new SolidBrush(Color.FromArgb(128, Color.Yellow));
spyGlass.BorderBackPen = new Pen(Color.Red);
spyGlass.BorderPen = new Pen(Color.Blue) { DashPattern = new float[] { 4.0F, 2.0F, 1.0F, 3.0F }};
spyGlass.Crosshair = ImageViewerSpyGlassCrosshair.Fine;
spyGlass.CrosshairPen = new Pen(Color.Green);
spyGlass.EnsureVisible = false;
spyGlass.Offset = new LeadPoint(0, 0);
spyGlass.HideCursorWhileWorking = true;
spyGlass.IdleCursor = Cursors.Cross;
spyGlass.RoundRectangleRadius = new LeadSize(25, 25);
spyGlass.Shape = ImageViewerSpyGlassShape.RoundRectangle;
spyGlass.Size = new LeadSize(200, 200);
// Get inverted copy of the RasterImage in the Viewer control
RasterImage invertedRasterImage = _imageViewer.Image.Clone();
InvertCommand invertCommand = new InvertCommand();
invertCommand.Run(invertedRasterImage);
// Overlay the inverted image on the spy glass
spyGlass.DrawImage += (object sender, ImageViewerSpyGlassDrawImageEventArgs e) =>
{
Image img = RasterImageConverter.ChangeToImage(invertedRasterImage, new ChangeToImageOptions());
e.Context.DrawImage(img, Point.Empty);
_form.Text =
$"Destination Rectangle: (" +
$"{e.DestinationRectangle.X}, {e.DestinationRectangle.Y}, {e.DestinationRectangle.Width}, {e.DestinationRectangle.Height}), " +
$"Offset: {e.Offset.X}, {e.Offset.Y}";
};
// Add spyglass interactive mode
_imageViewer.InteractiveModes.BeginUpdate();
_imageViewer.InteractiveModes.Add(spyGlass);
_imageViewer.InteractiveModes.EndUpdate();
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document