←Select platform

MagnifyGlassEffect Class

Summary
Creates an effect that can be used to zoom in on a portion of an image with options to specify size, shape and color of the magnify glass and crosshairs.
Syntax
C#
C++/CLI
public class MagnifyGlassEffect : ShaderEffect 
public ref class MagnifyGlassEffect : public System.Windows.Media.Effects.ShaderEffect, System.Windows.Media.Animation.IAnimatable   
Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.Windows.Controls; 
using Leadtools.Windows.Media; 
using Leadtools.Windows.Media.Effects; 
 
class MagnifyGlassEffectExampleWindow : Window 
{ 
   private ImageViewer theViewer; 
 
   public MagnifyGlassEffectExampleWindow() 
   { 
      StackPanel sp = new StackPanel(); 
      Content = sp; 
 
      theViewer = new ImageViewer(); 
 
      theViewer.HorizontalAlignment = HorizontalAlignment.Center; 
      theViewer.VerticalAlignment = VerticalAlignment.Top; 
      theViewer.ImageHorizontalAlignment = HorizontalAlignment.Left; 
      theViewer.ImageVerticalAlignment = VerticalAlignment.Top; 
 
      sp.Children.Add(theViewer); 
 
      // Load an image into the viewer 
      theViewer.Source = new BitmapImage(new Uri(System.IO.Path.Combine(LEAD_VARS.ImagesDir, "Cannon.jpg"))); 
 
      Title = "MagnifyGlassEffect - Click and and move the mouse cursor on the image to see the effect"; 
 
      theViewer.PreviewMouseDown += new MouseButtonEventHandler(theViewer_PreviewMouseDown); 
      theViewer.MouseMove += new MouseEventHandler(theViewer_MouseMove); 
      theViewer.MouseUp += new MouseButtonEventHandler(theViewer_MouseUp); 
   } 
 
   private void theViewer_PreviewMouseDown(object sender, MouseButtonEventArgs e) 
   { 
      MagnifyGlassEffect effect = new MagnifyGlassEffect(); 
 
      Point pos = e.GetPosition(theViewer); 
 
      BitmapSource source = theViewer.Source as BitmapSource; 
      if (source != null) 
      { 
         effect.Center = new Point( 
            (1.0 * pos.X) / source.PixelWidth, 
            (1.0 * pos.Y) / source.PixelHeight); 
 
         effect.Radius = 0.25; 
         effect.AspectRatio = 1.0; 
         effect.ScaleFactor = 2.0; 
         effect.Color = Colors.Blue; 
         effect.Border = 1; 
         effect.CrossHairs = 1; 
         theViewer.ImageEffect = effect; 
      } 
   } 
 
   private void theViewer_MouseMove(object sender, MouseEventArgs e) 
   { 
      MagnifyGlassEffect effect = theViewer.ImageEffect as MagnifyGlassEffect; 
      if (effect != null) 
      { 
         Point pos = e.GetPosition(theViewer); 
 
         BitmapSource source = theViewer.Source as BitmapSource; 
         if (source != null) 
         { 
            effect.Center = new Point( 
               (1.0 * pos.X) / source.PixelWidth, 
               (1.0 * pos.Y) / source.PixelHeight); 
         } 
      } 
   } 
 
   private void theViewer_MouseUp(object sender, MouseButtonEventArgs e) 
   { 
      if (theViewer.ImageEffect != null) 
      { 
         theViewer.ImageEffect = null; 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
Requirements

Target Platforms

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

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