Results 1 to 4 of 4

Thread: Picture Aspect Ratio on load picture (Not resize)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    104

    Picture Aspect Ratio on load picture (Not resize)

    Hi dear friends, I have a Picture previewer and I want to preview pictures in the ratio fit to the PictureBox, I used (Image1) to stretch the pictures but it is not cool for all pictures they lose the aspect ratio, How can I make it? How to make pictures fit to the PictureBox?
    *******************
    Picture below:
    No.1: is a (Picture1) PictureBox, has not stretch!
    No.2 is an (Image1) ImageBox, and stretched!

    Name:  wfr.jpg
Views: 531
Size:  48.6 KB

    Please show me a way to solve this problem!

  2. #2
    The Idiot
    Join Date
    Dec 2014
    Posts
    3,001

    Re: Picture Aspect Ratio on load picture (Not resize)

    u calculate the ratio from the original picture, ratio = width / height
    now, you can do in different ways, one way is to compare the ratio, assume you want a 4:3 ratio that means 1.333
    if the ratio is below 1.333 we use the preview width as "base" while the height we do width / 1.333
    if ratio is higher 1.333 we we the preview height as "base" while the width we do height * 1.333

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    104

    Re: Picture Aspect Ratio on load picture (Not resize)

    Quote Originally Posted by baka View Post
    u calculate the ratio from the original picture, ratio = width / height
    now, you can do in different ways, one way is to compare the ratio, assume you want a 4:3 ratio that means 1.333
    if the ratio is below 1.333 we use the preview width as "base" while the height we do width / 1.333
    if ratio is higher 1.333 we we the preview height as "base" while the width we do height * 1.333
    Thank you dear baka, Can you show me in a clearer method (if it is possible with a simple project)? really this is not clear for me!

  4. #4
    The Idiot
    Join Date
    Dec 2014
    Posts
    3,001

    Re: Picture Aspect Ratio on load picture (Not resize)

    to get you started:

    Dim Ratio!

    Ratio = Picture1.Width / Picture1.Height
    Image1.Width = 1000
    Image1.Height = 1000 / Ratio

    if you want the Height to be "fixed" you do

    Image1.Width = 1000 * Ratio
    Image1.Height = 1000

    ---

    You can change 1000 with the dimension you want.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width