-
June 28th, 2013, 07:54 AM
#1
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.
Last edited by GremlinSA; July 1st, 2013 at 01:54 AM.
Reason: Added Code tags...
-
June 28th, 2013, 08:03 AM
#2
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.
-
June 29th, 2013, 02:29 PM
#3
Re: Zoomed picture box image size.
Use CODE TAGS to preserve formatting. You can EDIT your post to add it.
-
July 1st, 2013, 02:10 AM
#4
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)..
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
July 1st, 2013, 03:42 AM
#5
Re: Zoomed picture box image size.
Ah yes, I didn't think of that.
Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|