[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1450
  • Last Modified:

VB.NET 2005 picturebox: resizing and retaining aspect ratio

Hello.  I have a VB.NET 2005 picturebox to work with.  I also have several images that vary in size.  When an image is loaded into the picturebox, I want to resize the image so that it has a width of 500, and I want to retain the aspect ratio for the height.  So, it should be resized to 500 x ? and be fully displayed in a form (not clipped and not stretched).  How do I go about this?
0
adwooley2
Asked:
adwooley2
1 Solution
 
Wayne Taylor (webtubbs)Commented:
Hello adwooley2,

try something like this....

        Dim img As Image = Image.FromFile("C:\YourFile.JPG")
        PictureBox1.Height = img.Height / (img.Width / 500)
        PictureBox1.Width = 500
        PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
        PictureBox1.Image = img

Regards,

Wayne
0
 
adwooley2Author Commented:
Well, I adapted what you had.  Thanks for your simple solution!

Regards,
Alan
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now