LEADTOOLS WPF and Silverlight (Leadtools.Windows.Controls assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.30
PointToImageCoordinates Method
See Also 
Leadtools.Windows.Controls Namespace > ImageViewer Class : PointToImageCoordinates Method



point
The source point in control (display) coordinates.
point
The source point in control (display) coordinates.
Converts a point from control (display) to image coordinates. Supported in Silverlight, Windows Phone 7

Syntax

Visual Basic (Declaration) 
Public Overridable Function PointToImageCoordinates( _
   ByVal point As Point _
) As Point
Visual Basic (Usage)Copy Code
Dim instance As ImageViewer
Dim point As Point
Dim value As Point
 
value = instance.PointToImageCoordinates(point)
C# 
public virtual Point PointToImageCoordinates( 
   Point point
)
C++/CLI 
public:
virtual Point PointToImageCoordinates( 
   Point point
) 

Parameters

point
The source point in control (display) coordinates.

Return Value

A System.Windows.Point that contains the converted values in image coordinates.

Example

Visual BasicCopy Code
Private Class PointToImageCoordinatesWindow : Inherits Window
         Private theImage As ImageViewer
         Public Sub New()
             ' Create the  viewer
             theImage = New ImageViewer()

             ' Create Dock Panel

             Dim panel As DockPanel = New DockPanel()
             Content = panel

             DockPanel.SetDock(theImage, Dock.Bottom)

             theImage.HorizontalAlignment = HorizontalAlignment.Center
             theImage.VerticalAlignment = VerticalAlignment.Bottom

             panel.Children.Add(theImage)

             ' load an image into the viewer
             theImage.Source = New BitmapImage(New Uri(Path.Combine(LEAD_VARS.ImagesDir, "cannon.jpg")))
             theImage.SizeMode = SizeMode.Fit

             Title = String.Format("Size mode = {0}, click to change", theImage.SizeMode)

             AddHandler theImage.MouseDown, AddressOf theImage_MouseClick
         End Sub

         Private Sub theImage_MouseClick(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
             Dim point As Point = theImage.PointToImageCoordinates(e.GetPosition(Me))

             Dim s As String = String.Format("Point accroding the image coordinates {0}", point.ToString())
             MessageBox.Show(s)
         End Sub
     End Class

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
C#Copy Code
class PointToImageCoordinatesWindow : Window
   {
      ImageViewer theImage;
      public PointToImageCoordinatesWindow()
      {
         // Create the  viewer
         theImage = new ImageViewer();

         // Create Dock Panel

         DockPanel panel = new DockPanel();
         Content = panel;

         DockPanel.SetDock(theImage, Dock.Bottom);

         theImage.HorizontalAlignment = HorizontalAlignment.Center;
         theImage.VerticalAlignment = VerticalAlignment.Bottom;

         panel.Children.Add(theImage);

         // load an image into the viewer
         theImage.Source = new BitmapImage(new Uri(Path.Combine(LEAD_VARS.ImagesDir, "cannon.jpg")));
         theImage.SizeMode = SizeMode.Fit;

         Title = string.Format("Size mode = {0}, click to change", theImage.SizeMode);

         theImage.MouseDown += new MouseButtonEventHandler(theImage_MouseClick);
      }

      void theImage_MouseClick(object sender, MouseButtonEventArgs e)
      {
         Point point = theImage.PointToImageCoordinates(e.GetPosition(this));

         string s = string.Format("Point accroding the image coordinates {0}", point.ToString());
         MessageBox.Show(s);
      }
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
SilverlightCSharpCopy Code
class PointToImageCoordinatesWindow : ChildWindow
{
   ImageViewer theImage;
   public PointToImageCoordinatesWindow()
   {
      // Create the  viewer
      theImage = new ImageViewer();

      // Create Dock Panel

      StackPanel panel = new StackPanel();
      Content = panel;

      theImage.HorizontalAlignment = HorizontalAlignment.Center;
      theImage.VerticalAlignment = VerticalAlignment.Bottom;

      panel.Children.Add(theImage);

      // load an image into the viewer
      theImage.Source = new BitmapImage(new Uri(LeadtoolsExamples.Common.ImagesPath.Path + "cannon.jpg"));
      theImage.SizeMode = SizeMode.Fit;

      Title = string.Format("Size mode = {0}, click to change", theImage.SizeMode);

      theImage.MouseLeftButtonDown += new MouseButtonEventHandler(theImage_MouseLeftButtonDown);
   }

   void theImage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
   {
      Point point = theImage.PointToImageCoordinates(e.GetPosition(this));

      string s = string.Format("Point accroding the image coordinates {0}", point.ToString());
      MessageBox.Show(s);
   }
}
SilverlightVBCopy Code
Private Class PointToImageCoordinatesWindow : Inherits ChildWindow
   Private theImage As ImageViewer
   Public Sub New()
      ' Create the  viewer
      theImage = New ImageViewer()

      ' Create Dock Panel

      Dim panel As StackPanel = New StackPanel()
      Content = panel

      theImage.HorizontalAlignment = HorizontalAlignment.Center
      theImage.VerticalAlignment = VerticalAlignment.Bottom

      panel.Children.Add(theImage)

      ' load an image into the viewer
      theImage.Source = New BitmapImage(New Uri(LeadtoolsExamples.Common.ImagesPath.Path & "cannon.jpg"))
      theImage.SizeMode = SizeMode.Fit

      Title = String.Format("Size mode = {0}, click to change", theImage.SizeMode)

      AddHandler theImage.MouseLeftButtonDown, AddressOf theImage_MouseLeftButtonDown
   End Sub

   Private Sub theImage_MouseLeftButtonDown(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
      Dim point As Point = theImage.PointToImageCoordinates(e.GetPosition(Me))

      Dim s As String = String.Format("Point accroding the image coordinates {0}", point.ToString())
      MessageBox.Show(s)
   End Sub
End Class

Remarks

The viewer control contain many properties that control how the image will be displayed on the surface of the control. At any time, you might require to convert a point or a rectangle from control (where it is on the surface of the control) to image (the pixel x and y value in the image data) and vice versa.

Use PointToImageCoordinates to convert a point from control to image coordinates, use PointFromImageCoordinates to convert a point from image to control coordinates. Use BoundsToImageCoordinates to convert a rectangle value from control to image coordinates and BoundsFromImageCoordinates to convert a rectangle value from image to control coordinates.

Note that when using the RasterImageBox and RasterImageViewer controls to display a LEADTOOLS Leadtools.RasterImage object, the image coordinates are assumed to be in top-left view perspective. If the image contains a RasterImage.ViewPerspective value other than RasterViewPerspective.TopLeft you must call RasterImage.PointToImage or RasterImage.RectangleToImage to further convert the values to actual rows and columns pixel values in the image.

Requirements

Target Platforms: Windows 2000, Windows XP, Windows Server 2003 family, Windows Server 2008 family

See Also