[英]How can I get the actual coordinates of the image when I click on the pictureBox whose size property is set to CenterImage in winForms?
The resolution of image is 4000x7000 and size of picture box is 500x600.图像分辨率为4000x7000,图片框尺寸为500x600。
private void pictureBoxZoom_Click(object sender, EventArgs e)
{
MouseEventArgs me = (MouseEventArgs)e;
string message = "X="
+ (image.Width * me.X / pictureBox1.Width)
+ ", Y="
+ (image.Height * me.Y / pictureBox1.Height);
MessageBox.Show(message);
}
As the picturebox size mode property is set to centerImage.由于图片框大小模式属性设置为 centerImage。 We can calculate the centre coordinates of the image.
我们可以计算图像的中心坐标。 After getting the centre coordinates we can subtract mouse location from half the size of picture box and we will get the desired result.
得到中心坐标后,我们可以从图片框大小的一半中减去鼠标位置,我们将得到所需的结果。 I have added padding as well into the calculations as in my case when I would centre the image the pictures gets some padding as well.
我已经在计算中添加了填充,就像在我将图像居中时,图片也会得到一些填充。 In my case I had to divide the paddings with 2, but I have removed that from here as I'm not sure if that would be the case for everyone.
就我而言,我必须将填充物与 2 分开,但我已将其从此处删除,因为我不确定是否每个人都如此。
point.X = ((pictureBoxZoom.Image.Width / 2) + (pictureBoxZoom.Padding.Right) - (pictureBoxZoom.Padding.Left) - ((pictureBoxZoom.Width / 2) - me.X));
point.Y = ((pictureBoxZoom.Image.Height / 2) - (pictureBoxZoom.Padding.Top) + (pictureBoxZoom.Padding.Bottom) - ((pictureBoxZoom.Height / 2) - me.Y));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.