-
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
-
See the AutoSize property to True. (either at design time or runtime)
Code:
Picture1.AutoSize = True
-
i tried that and it didn't work.
is there some specific formula to adjust the
picture dimensions to the picture object?
-
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
-
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