How to get the value of non-public participants in Photoshop?

I need to get the image rectangle value from non-public image elements.

How to get this value?

Thanks in advance.

+6
c #
source share
3 answers

Here's how to get the value using reflection:

PropertyInfo pInfo = pictureBox1.GetType().GetProperty("ImageRectangle", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); Rectangle rectangle = (Rectangle)pInfo.GetValue(pictureBox1, null); 

Although, as John said, there may be a better way to achieve what you are trying to do. Access to private members through reflection is usually a pretty big smell of code.

+9
source share

Well, you could do it with reflection ... but you shouldn't. It's not clear what you mean by โ€œimage rectangle valueโ€, but you should definitely try to do all this through the public API. What are you trying to achieve? There may be another way.

EDIT: Okay, now I see a property you're trying to access ... you might be interested in this Connect issue filed in 2004. You are not the only one who wants this ... although if you need it for the same reason or not, I do not know.

+2
source share

Despite the fact that Nivas did not indicate what he wants to achieve, I suspect that it looks like what I just looked at - translating a rectangle with a drawing (i.e. I did not try to inherit, as suggested by RvdK, I used a reflection method as a quick workaround. An alternative to RvdK's suggestion or opening Microsoft to access ImageRectangle would be to provide a RectangleToImageRectangle method. Which I suppose I could wrap an object that inherits from PB ...

Disabled Microsoft Connect Issue link.

Here is the code I used, it provides a rectangle of the PB image and has been tested for .Zoom and .StretchImage modes:

 PropertyInfo pInfo = pictureBox1.GetType().GetProperty("ImageRectangle", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); Rectangle ImRectangle = (Rectangle)pInfo.GetValue(pictureBox1, null); Point rTL = new Point((rectCropArea.Left - ImRectangle.Left) * pictureBox1.Image.Width / ImRectangle.Width, (rectCropArea.Top - ImRectangle.Top) * pictureBox1.Image.Height / ImRectangle.Height); Size rSz = new Size(pictureBox1.Image.Width * rectCropArea.Width / ImRectangle.Width, pictureBox1.Image.Height * rectCropArea.Height / ImRectangle.Height); 'rect' = new Rectangle(rTL,rSz); 
0
source share

All Articles