|
-
Dec 13th, 2010, 04:22 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Find the display size of an image in a picturebox
Is there a way to tell the DISPLAY size of an image in a picture box?
If the PictureBox.SizeMode=Zoom, the picture sometimes is not displayed as big as the picture box is, and is sometimes displayed smaller, or larger, than the actual image is.
I just want to know what size it is actually displaying as.
Thanks
Greg
-
Dec 13th, 2010, 05:09 PM
#2
Re: Find the display size of an image in a picturebox
try this:
vb Code:
dim img as bitmap = directcast(picturebox1.image.clone, bitmap)
dim width as integer = img.width
dim height as integer = img.height
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Dec 13th, 2010, 05:58 PM
#3
Re: Find the display size of an image in a picturebox
Here's my take on it. If the shape of the original image is wider and flatter than the picture box, the zoomed width will equal the width of the picturebox. If the shape of the image is taller and narrower than that of the picturebox, the height of the zoomed image will equal the picturebox height. So you have to compare the aspect ratios (height divided by width):
Code:
Private Function GetZoomedSize(ByVal img As Image, ByVal pb As PictureBox) As Size
Dim imgAspectRatio As Double = img.Height / img.Width
Dim pbAspectRatio As Double = pb.ClientSize.Height / pb.ClientSize.Width
If imgAspectRatio > pbAspectRatio Then 'image shape is taller than pb
Return New Size(CInt(pb.ClientSize.Height / imgAspectRatio), pb.ClientSize.Height)
Else 'image shape is wider than pb
Return New Size(pb.ClientSize.Width, CInt(pb.ClientSize.Width * imgAspectRatio))
End If
End Function
BB
Last edited by boops boops; Dec 13th, 2010 at 06:12 PM.
Reason: corrected error in code, line 5
-
Dec 14th, 2010, 09:54 AM
#4
Thread Starter
Hyperactive Member
Re: Find the display size of an image in a picturebox
Thank you for the help.
Boops boops: That is a great idea, can't believe I didn't think of that! Thanks, it worked perfectly. 
.paul.: Your solution returns the size of the original image, not the currently displayed size.
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
|