I am using a zoomed picturebox. I want to retrieve the image Top-Left and Bottom-Right coordinates. But it is different from that of picturebox when the aspect ratio of the image doesn't match the picturebox. I wonder how I can get the image coordinates on the form.
Asked
Active
Viewed 3,023 times
1
-
You can use the pbox.ClientSize and the pbox.Image.size to calculate it.. Top-Left will always be (0,0).. What does _image coordinates on the form_ mean?? – TaW Jun 29 '16 at 07:40
-
Top-left is *not* (0, 0) in zoom mode. Just reason it out with a tall and narrow image. Consider using reflection to access the [ImageRectangle property](http://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/PictureBox.cs,d19be1af32c23a82). – Hans Passant Jun 29 '16 at 08:06
2 Answers
0
Minus the Image
size divided by 2 from the PictureBox
size plus the Image
size again.
This uses the Size.Subtract Method (Size, Size)
. MSDN
Size sizestep1 = Size.Subtract(new Size(PictureBox1.Image.Size.Width / 2, PictureBox1.Image.Size.Height / 2), PictureBox1.Size);
Size finalsize = Size.Add(sizestep1, PictureBox1.Image.Size);
// Convert to point.
Point BottomRightCoords = new Point(finalsize.Width, finalsize.Height);
And if you want to get the BottomRightCoords on the form, you have to add the PictureBox
Location to it.
0
A little bit of mathematics suggested above + the code in the following link did the trick: How to retrieve zoom factor of a WinForms PictureBox?

Community
- 1
- 1

Arash Vahabpour
- 11
- 1
- 3