Auto resizing a picture to fit
Posted on 2003-11-24
When I load a picture into a picture object, it's too big and is truncated to the right and bottom. So I am trying to re-size it.
I tried 2 things:
1. Picture.AutoSize = true
It complains that "Method or data member not found". I am using VB6.
2. A solution I found at this site:
Dim AspectRatio As Single
Dim NewHeight As Long
Dim TmpPic As StdPictureSet Picture1.Picture = LoadPicture("pic")
AspectRatio = TmpPic.Width / TmpPic.Height
NewHeight = Picture1.ScaleWidth / AspectRatio
Picture1.AutoRedraw = True ' Necessary to keep the picture from being erased when window gets repainted
Picture1.PaintPicture TmpPic, 0, (Picture1.ScaleHeight - NewHeight) / 2, Picture1.ScaleWidth, NewHeight
' Arguments are as follows: Source picture, Destination X, Destination Y, New Width, New Height
It also complains that "Method or data member not found" at Picture1.ScaleWidth
Thank you for your help.