简体   繁体   English

winForms中点击size属性设置为CenterImage的pictureBox如何获取图片的实际坐标?

[英]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.

相关问题 单击pictureBox时,如何将鼠标光标坐标转换为屏幕相对鼠标光标坐标? - How can I convert the mouse cursor coordinates when click on pictureBox are to the screen relative mouse cursor coordinates? 我应该如何在 WinForms PictureBox 中将屏幕空间坐标转换为图像空间坐标? - How should I translate from screen space coordinates to image space coordinates in a WinForms PictureBox? 如何才能逐渐且平滑地更改PictureBox的大小? (在Winforms中,C#,Visual Studio 2013) - How can I change PictureBox size incrementally and smoothly ? ( in winforms , c# , visual studio 2013 ) 为什么在粘贴到 Excel 时图像显示的大小大于其实际大小,我如何才能使其以自然大小显示? - Why does an image display at greater that its actual size when pasting into Excel, and how can I get it to display at its natural size? 如何在Winforms图片框上使图形线条正确匹配? - How can I get my graphics lines to match up properly on Winforms picturebox? 如何在Picturebox中获取光标在图像上的确切位置 - How can I get the exact location of cursor on image in Picturebox 如何更改PictureBox的尺寸? - How can I change size of PictureBox? 我可以在WinForms的PictureBox上创建透明背景吗? - Can I create a transparent background on a PictureBox in WinForms? 我有两个其他尺寸的pictureBox,当我单击一个pictureBox时,如何在较小的pictureBox上绘制一个点,该怎么做? - I have two pictureBoxes in other sizes how can i make that when i click on one pictureBox it will draw a point on the smaller pictureBox? 如何通过使用OpenFileDialog设置PictureBox控件的Image属性? C#Winforms - How to set the Image property of a PictureBox Control by using OpenFileDialog? C# winforms
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM