简体   繁体   English

如何获取图片框的基础图像的坐标

[英]how to get the co-ordinates of an underlying image of a picture box

I have a picture box with an image associated with it. 我有一个带有与之相关的图片的图片框。

The size mode of the PictureBox has been set to CenterImage PictureBox的大小模式已设置为CenterImage

My question is how can I get the image co-ordinates for that underlying image. 我的问题是如何获得底层图像的图像坐标。

Regards 问候

I think your best bet is to calculate it yourself using a formula like this: 我认为您最好的选择是使用以下公式自己计算:

int xOffset = (pictureBox1.Width / 2) - (pictureBox1.Image.Width / 2);
int yOffset = (pictureBox1.Height / 2) - (pictureBox1.Image.Height / 2);

xOffset and yOffset should equal the (x,y) of the image from the top left corner of the picture box. xOffset和yOffset应该等于图片框左上角图像的(x,y)。 Keep in mind, the formula above uses integer math and it could truncate values. 请记住,上面的公式使用整数数学,它可能会截断值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM