←Select platform

ImageViewer Property

Summary

Image Viewer for this mode.

Syntax
C#
Objective-C
C++/CLI
public virtual ImageViewer ImageViewer { get; } 
@property (nonatomic, strong, readonly, nullable) LTImageViewer *imageViewer; 
public:  
   virtual property ImageViewer^ ImageViewer 
   { 
      ImageViewer^ get() 
   } 

Property Value

The image viewer for this mode.

Remarks

This value is useful when deriving your own interactive mode classes. Refer to ImageViewerInteractiveMode for an example.

Example
C#
using Leadtools; 
using Leadtools.Controls; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
 
private class TransformInteractiveMode : ImageViewerInteractiveMode 
{ 
   public TransformInteractiveMode() : 
      base() 
   { 
      this.AutoItemMode = ImageViewerAutoItemMode.AutoSet; 
   } 
 
   private Keys _scaleKeyModifier = Keys.Control; 
   public virtual Keys ScaleKeyModifier 
   { 
      get { return _scaleKeyModifier; } 
      set 
      { 
         // Supported is none and any modifiers 
         switch (value) 
         { 
            case Keys.None: 
            case Keys.Alt: 
            case Keys.Shift: 
            case Keys.Control: 
               _scaleKeyModifier = value; 
               break; 
 
            default: 
               throw new ArgumentException("Invalid value", "ScaleKeyModifier"); 
         } 
      } 
   } 
 
   private Keys _rotateKeyModifier = Keys.Alt; 
   public virtual Keys RotateKeyModifier 
   { 
      get { return _rotateKeyModifier; } 
      set 
      { 
         // Supported is none and any modifiers 
         switch (value) 
         { 
            case Keys.None: 
            case Keys.Alt: 
            case Keys.Shift: 
            case Keys.Control: 
               _rotateKeyModifier = value; 
               break; 
 
            default: 
               throw new ArgumentException("Invalid value", "PageKeyModifier"); 
         } 
      } 
   } 
 
   public override string Name 
   { 
      get { return "Transform"; } 
   } 
 
   public override int Id 
   { 
      get { return ImageViewerInteractiveMode.UserModeId + 3; } 
   } 
 
   public override void Start(ImageViewer imageViewer) 
   { 
      base.Start(imageViewer); 
      var service = base.InteractiveService; 
 
      // Pan required events 
      service.DragStarted += new EventHandler<InteractiveDragStartedEventArgs>(service_DragStarted); 
      service.DragDelta += new EventHandler<InteractiveDragDeltaEventArgs>(service_DragDelta); 
      service.DragCompleted += new EventHandler<InteractiveDragCompletedEventArgs>(service_DragCompleted); 
      service.DoubleTap += new EventHandler<InteractiveEventArgs>(service_DoubleTap); 
   } 
 
   public override void Stop(ImageViewer imageViewer) 
   { 
      if (IsStarted) 
      { 
         var service = base.InteractiveService; 
 
         service.DragStarted -= new EventHandler<InteractiveDragStartedEventArgs>(service_DragStarted); 
         service.DragDelta -= new EventHandler<InteractiveDragDeltaEventArgs>(service_DragDelta); 
         service.DragCompleted -= new EventHandler<InteractiveDragCompletedEventArgs>(service_DragCompleted); 
         service.DoubleTap -= new EventHandler<InteractiveEventArgs>(service_DoubleTap); 
 
         base.Stop(imageViewer); 
      } 
   } 
 
   private void service_DragStarted(object sender, InteractiveDragStartedEventArgs e) 
   { 
      // Make sure pinch is not working, otherwise, ignore pan 
      if (!this.CanStartWork(e)) 
         return; 
 
      // Make sure we are on an item 
      if (this.Item == null) 
         return; 
 
      e.IsHandled = true; 
      this.OnWorkStarted(EventArgs.Empty); 
   } 
 
   private void service_DragDelta(object sender, InteractiveDragDeltaEventArgs e) 
   { 
      if (!this.IsWorking) 
         return; 
 
      var item = this.Item; 
      if (item == null) 
         return; 
 
      // Find out what to do 
      var dx = e.Change.X; 
      var dy = e.Change.Y; 
 
      if (dx == 0 && dy == 0) 
         return; 
 
      var scaleKeyModifier = this.ScaleKeyModifier; 
      var rotateKeyModifier = this.RotateKeyModifier; 
      var scale = (Control.ModifierKeys & scaleKeyModifier) == scaleKeyModifier; 
      var rotate = (Control.ModifierKeys & rotateKeyModifier) == rotateKeyModifier; 
 
      var imageViewer = this.ImageViewer; 
 
      if (scale) 
      { 
         Scale(imageViewer, item, dy, e.Origin); 
      } 
      else if (rotate) 
      { 
         Rotate(imageViewer, item, dx, e.Origin); 
      } 
      else 
      { 
         Translate(imageViewer, item, dx, dy); 
      } 
 
      e.IsHandled = true; 
   } 
 
   private void service_DragCompleted(object sender, InteractiveDragCompletedEventArgs e) 
   { 
      if (!this.IsWorking) 
         return; 
 
      e.IsHandled = true; 
      OnWorkCompleted(EventArgs.Empty); 
   } 
 
   private void service_DoubleTap(object sender, InteractiveEventArgs e) 
   { 
      // Make sure we not working already 
      if (this.IsWorking || !this.CanStartWork(e)) 
         return; 
 
      // Make sure we have an item 
      var item = this.Item; 
      if (item == null) 
         return; 
 
      e.IsHandled = true; 
 
      this.OnWorkStarted(EventArgs.Empty); 
      Identity(this.ImageViewer, item); 
      this.OnWorkCompleted(EventArgs.Empty); 
   } 
 
   private void Identity(ImageViewer imageViewer, ImageViewerItem item) 
   { 
      item.Transform = LeadMatrix.Identity; 
   } 
 
   private void Scale(ImageViewer imageViewer, ImageViewerItem item, int dy, LeadPoint position) 
   { 
      // ... 
      // set scale code 
      // ... 
   } 
 
   private void Rotate(ImageViewer imageViewer, ImageViewerItem item, int dx, LeadPoint position) 
   { 
      // ... 
      // set rotate code 
      // ... 
   } 
 
   private void Translate(ImageViewer imageViewer, ImageViewerItem item, int dx, int dy) 
   { 
      // ... 
      // set translate code 
      // ... 
   } 
} 
 
public void ImageViewerInteractiveMode_Example() 
{ 
   _imageViewer.InteractiveModes.BeginUpdate(); 
   _imageViewer.InteractiveModes.Add(new TransformInteractiveMode { IsEnabled = false }); 
   //... 
   //... 
   //... 
   _imageViewer.InteractiveModes.EndUpdate(); 
} 
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.