CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 1999
    Location
    G day Mayt Land
    Posts
    971

    [RESOLVED] avoid stretching an image but in a fixed size

    I am displaying an Image in a fixed size section of screen say X and Y
    If the picture happend to be smaller or bigger I use stretch to fit it in my area of control.
    Now the area could be wider or taller and .tretch woudl make it look unproportinal.

    Without any mathematical calculation that I m trying to avoid,
    is there any way that VB6 could resize that image keeping the same aspect ration and only use the area X & Y.
    of course that may mean i ll endup with some extra space unused at the bottom or on the right which is undeatndable.

    But can this be done via image property and VB6 ?
    a sample of the code:
    Code:
        Image1(j).Visible = True
                    Image1(j).Width = getValue(str0, "Width")
                    Image1(j).Height = getValue(str0, "Height")
                    Image1(j).Stretch = True
    
                    Image1(j).Top = Label6(j).Top + Label6(j).Height
                    Image1(j).Left = Label6(j).Left
    Last edited by Saeed; July 4th, 2010 at 10:32 PM.

  2. #2
    Join Date
    Apr 2009
    Posts
    394

    Re: avoid stretching an image but in a fixed size

    Nope,... You will need to use just a little bit of simple math...

    pseudo code...

    if height > width then
    percentage = width / height
    elseif width > height then
    percentage = height / width
    else
    percentage = 1
    endif

    Okay, the above pseudo code shows you how to figure out your aspect ratio calculation so you won't "stretch" the short end (h or w) when resizing...



    Good Luck

  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: avoid stretching an image but in a fixed size

    Hello Saeed!

    This may also be useful to you :

    http://www.codeguru.com/forum/showthread.php?t=497592

  4. #4
    Join Date
    May 1999
    Location
    G day Mayt Land
    Posts
    971

    Resolved Re: avoid stretching an image but in a fixed size

    Thanks Hanne;
    Good work .

    Cheers

  5. #5
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: [RESOLVED] avoid stretching an image but in a fixed size



    Glad I could help

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

Featured