Get Click Coordinates Relative to the Image of RadImageEditor
Environment
Product Version | 2021.2.511 |
Product | RadImageEditor for WPF |
Description
How to get the image cooridnates of the clicked point in the RadImageEditor control.
Solution
To do this, you can subscribe to the MouseLeftButtonDown event of RadImageEditor and calculate the coordinates based on the mouse position, the image size and the control's size.
private void imageEditor_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
var image = e.OriginalSource as Image;
if (image != null)
{
Point mousePosition = e.GetPosition(image);
double relativeWidth = mousePosition.X / image.ActualWidth;
double relativeHeight = mousePosition.Y / image.ActualHeight;
var originalImageWidth = ((WriteableBitmap)image.Source).PixelWidth;
var originalImageHeight = ((WriteableBitmap)image.Source).PixelHeight;
var pixelXPosition = originalImageWidth * relativeWidth;
var pixelYPosition = originalImageHeight * relativeHeight;
}
}