Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the dimensions of the ImageRectangle in PictureBox?

Background

I want to be able to get the drawn dimensions of a zoomed image inside the picturebox (I'll explain below).

The PictureBox.ImageRectangle property seems to be exactly what I'm looking for because it shows the height and width of the resized image, as well as it's relative top, left position inside the control.

The trouble is PictureBox.ImageRectangle is private and so I can't read the values without using reflection (which is obviously not ideal).

Actual Question

My question is, is there another way that I can easily get to these values without writing a method to calculate what the values "ought" to be? I can do that easily enough, but I feel I'd be reinventing the wheel.


Context:

I'm writing a simple image processing app in C# and one of the things it has to do is allow the user to draw a selection around a portion of the image (a lot like the Marquee tool in Photoshop).

I need to know the dimensions of the rendered image so I know where to set the bounds of my marquee tool and also to translate the values of the drawn rectangle to points on the scaled bitmap inside the control.

like image 936
Iain Fraser Avatar asked Nov 04 '22 13:11

Iain Fraser


1 Answers

My answer look simple so maybe I'm missing something, but I think Control.DisplayRectangle suits your need.

EDIT

OK, missed the point; however see How to get the value of non- public members of picturebox?

like image 87
CharlesB Avatar answered Nov 15 '22 05:11

CharlesB