如何从PictureBox中的Image获取位置

时间:2020-12-25 09:00:52

I've a question. Do someone know how I can get the position of an centered image in a Picturebox?

我有一个问题。有人知道如何在Picturebox中获得居中图像的位置吗?

I need the X and Y coordinates but currently I'dn't have any idea.

我需要X和Y坐标,但目前我不知道。

Thank you in advance.

先谢谢你。

2 个解决方案

#1


2  

If picture box is bigger than image, you can try to calculate image's absolute position on the form:

如果图片框大于图片,您可以尝试在图片上计算图片的绝对位置:

int absImgX=pictureBox1.Left+pictureBox1.Width/2-pictureBox1.Image.Width/2
int absImgY=pictureBox1.Top+pictureBox1.Height/2-pictureBox1.Image.Height/2

#2


0  

I have solved the problem with:

我用以下方法解决了这个问题:

_absoluteImagePositionX = imageBox.Width / 2 - image.Width / 2;
_absoluteImagePositionY = imageBox.Height / 2 - image.Height / 2;

But by the way thank you for your tips!

但顺便说一句,谢谢你的提示!

#1


2  

If picture box is bigger than image, you can try to calculate image's absolute position on the form:

如果图片框大于图片,您可以尝试在图片上计算图片的绝对位置:

int absImgX=pictureBox1.Left+pictureBox1.Width/2-pictureBox1.Image.Width/2
int absImgY=pictureBox1.Top+pictureBox1.Height/2-pictureBox1.Image.Height/2

#2


0  

I have solved the problem with:

我用以下方法解决了这个问题:

_absoluteImagePositionX = imageBox.Width / 2 - image.Width / 2;
_absoluteImagePositionY = imageBox.Height / 2 - image.Height / 2;

But by the way thank you for your tips!

但顺便说一句,谢谢你的提示!