Results 1 to 5 of 5

Thread: help with sizing picture in picture box

  1. #1
    Guest
    a user enters the directory and extension that
    then in turn loads the images into an array.
    if the image width and height are larger than the
    picture box, how can i resize the image to fit into
    the picture box without becoming distorted?
    i prefer not to use the image control in this situation.

    i have tried to use the scalewidth and scaleheight of the
    picture box, but can't seem to get it right,
    any suggestions to point me in right direction?

    thanks in advance,
    larryn



    'loop through the directory to find only the files
    'that the user chose by extension and load them into
    'an array
    For Each MyFile In MyFolder.Files
    If Mid$(MyFile.Name, Len(MyFile.Name) - 3) = Mid(sExt, 2, 4) Then
    'e.g. Mid(sExt, 2, 4) = jpg
    ReDim Preserve pics(iX)
    pics(iX) = MyFolder & "\" & MyFile.Name
    iX = iX + 1
    End If
    Next MyFile

    'loop through all the images that were found by
    'extension chosen and show them in the picure box
    'according to the time chosen by user for interval
    'between each image.
    For iX = LBound(pics()) To UBound(pics())
    Set Picture1.Picture = LoadPicture(pics(iX))

    Sleep (lTime)
    Next

  2. #2
    Guest
    See the AutoSize property to True. (either at design time or runtime)
    Code:
    Picture1.AutoSize = True

  3. #3
    Guest
    i tried that and it didn't work.

    is there some specific formula to adjust the
    picture dimensions to the picture object?



  4. #4
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    autosize should work

    You can test it out in design mode by making a small picturebox, setting the autosize to true and then specifying a bitmap to load. The picturebox will resize itself to fit the picture.

    If this works, but your code doesn't, then we need to look in your code for the problem.

    Cheers
    Paul Lewis

  5. #5
    Lively Member
    Join Date
    Jul 2000
    Posts
    94
    If you want to change the picture size, but want the dimensions to stay correct you can easily do that. First decide which to stay constant, the height or width then do some math and voila you are there.

    Code:
    Dim i As IPictureDisp, ratio As Double
    Set i = LoadPicture("AnyPicture.bmp")
    'for fixed width
    ratio = i.Height / i.Width
    Picture1.Height = Picture1.Width * ratio
    'for fixed height
    ratio = i.Width / i.Height
    Picture1.Width = Picture1.Height * ratio

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