Zoomed picture box image size.
Hi folks. I have a problem with getting the size of an image within a picture box, I'll try to explain as clearly as possible.
On a form I have a picture box, the picture box is anchored to all sides of the form and is set to zoom mode. It has to be zoom mode as I need to display very large images shrunk within the diemsions of the form.
A dialog is used to select a jpg image, which is loaded into a bitmap, the picturebox image property is then set to the bitmap object. I need to do it this way so I can keep an original copy of the image selected in memory.
The picture box correctly keeps its borders to the edge of the form and shrinks the largest dimension of the displayed image to keep the correct aspect ratio, the picture is displayed perfectly throughout form resizing.
For the sake of argument, I want to get the percentage location of a mouse click within the picture displayed, where top left is 0,0 and bottom right is 100,100.
The problem is I can't find a property within the picturebox that returns the actual size of the image displayed. I can either return the location compared to the actual size of the border, or the original image.
Code:
ooooooooooooooooooooooooooooooooooooooooooooooo
o xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx o
o x x o
o x x o
o x x o
o x x o
o x x o
o x x o
o x x o
o xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx o
ooooooooooooooooooooooooooooooooooooooooooooooo
picturebox.width returns the value for the o's.
picturebox.image.width returns the value of the original image.
I can't find a way to return the x,y,w,h values for the x's
Is there a way to do this easily, or am I going to have to calculate the picture height, width and placement on the form manually to get the correct values?
Any help would be appreciated.
Cheers.
Re: Zoomed picture box image size.
Ah, my o's and x's didn't display right.
Imagine the o's being a big rectangle, the x's being a smaller rectangle centered within.
Re: Zoomed picture box image size.
Use CODE TAGS to preserve formatting. You can EDIT your post to add it.
Re: Zoomed picture box image size.
You have two options here, and both of them are difficult...
#1).. Set the PictureBox to Normal or Center Image, and do the Image re-sizing yourself (using the Form Resize event), Taking care of all the math here is a little complicated, but very doable...(See the Crop/Zoom thread NOTE: that is VB6 Code, but the math is the same)
#2).. Just use the math and calculate the positions... Again the math is a little more complicated but also doable.. (see same thread as above for the math)..
Re: Zoomed picture box image size.
Ah yes, I didn't think of that.
Thanks.