Products | Support | Email a link to this topic. | Send comments on this topic. | Back to Introduction - All Topics | Help Version 19.0.5.10
|
Leadtools.Windows.Controls Namespace > ImageViewer Class : PointToImageCoordinates Method |
'Declaration Public Overridable Function PointToImageCoordinates( _ ByVal point As Point _ ) As Point
'Usage Dim instance As ImageViewer Dim point As Point Dim value As Point value = instance.PointToImageCoordinates(point)
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.
Imports Leadtools.Windows.Controls 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
using Leadtools.Help; using Leadtools.Windows.Controls; 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"; }
using Leadtools.Help; using Leadtools.Windows.Controls; 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); } }
Imports Leadtools Imports Leadtools.Windows.Controls 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