groundwar
asked on
VBA Picture Sizing
Perhaps I'm on glue or have been looking at this too long, but how do you resize a picture that you've loaded onto a form? Basically what I'm trying to do is have a client select a logo file from their computer and load it onto the form. Then I want the form to resize to a "BEST FIT" Ratio. So if their Logo is 800X200 and the Standard Logo insert size is 200X50, it will resize the image by a ratio of 25%. I know how to deduce the resize ratio, but I can't resize it. Here's my code:
--
'Org/Logo Options - Load Logos onto Form
Private Sub loadLogoButton_Click()
'Scaler Preportion
scaler = 26.46
'Check to see if logo selected
If logo <> "" Then
'Check if valid File Type
FileType = Right(logo, 3)
If FileType = "jpg" Or FileType = "jpeg" Or FileType = "gif" Then
'Load picture onto form
LargeLogoInsert.Picture = LoadPicture(logo)
SmallLogoInsert.Picture = LoadPicture(logo)
'Set best Fit Picture Size
logo_ratio = LargeLogoInsert.Picture.Wi dth / LargeLogoInsert.Picture.He ight
large_bestfit_ratio = 200 / LargeLogoInsert.Picture.Wi dth
large_bestfit_size = large_bestfit_ratio * LargeLogoInsert.Picture.Wi dth
'Change Picture Size to Match Best Fit
???? = large_bestfit_size
end sub
--
Thanks in advanced for your help.
--
'Org/Logo Options - Load Logos onto Form
Private Sub loadLogoButton_Click()
'Scaler Preportion
scaler = 26.46
'Check to see if logo selected
If logo <> "" Then
'Check if valid File Type
FileType = Right(logo, 3)
If FileType = "jpg" Or FileType = "jpeg" Or FileType = "gif" Then
'Load picture onto form
LargeLogoInsert.Picture = LoadPicture(logo)
SmallLogoInsert.Picture = LoadPicture(logo)
'Set best Fit Picture Size
logo_ratio = LargeLogoInsert.Picture.Wi
large_bestfit_ratio = 200 / LargeLogoInsert.Picture.Wi
large_bestfit_size = large_bestfit_ratio * LargeLogoInsert.Picture.Wi
'Change Picture Size to Match Best Fit
???? = large_bestfit_size
end sub
--
Thanks in advanced for your help.
ASKER
Close, but the picture control is the only thing that changes size. The picture remains the same size. I thought that using the autosize would help the situation but it doesn't so what I end up with is a picture that is cropped cause the Control is smaller than the picture loaded in it. Do I have to load the picture into the control?
--
My glue habit continues.
--
My glue habit continues.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Adding -> LargeLogoInsert.PictureSiz eMode = fmPictureSizeModeStretch made the world of difference. bhagyesht, you're right. Thanks for the help. In case anybody is looking for how it all looked in the end I've attached it below.
--
'Org/Logo Options - Load Logos onto Form
Private Sub loadLogoButton_Click()
'Check to see if logo selected
If logo <> "" Then
'Check if valid File Type
FileType = Right(logo, 3)
If FileType = "jpg" Or FileType = "jpeg" Or FileType = "gif" Then
'Load picture onto form
LargeLogoInsert.PictureSiz eMode = fmPictureSizeModeStretch
SmallLogoInsert.PictureSiz eMode = fmPictureSizeModeStretch
LargeLogoInsert.Picture = LoadPicture(logo)
SmallLogoInsert.Picture = LoadPicture(logo)
'Set best Fit Picture Size
aspect_ratio = LargeLogoInsert.Picture.Wi dth / LargeLogoInsert.Picture.He ight
If LargeLogoInsert.Picture.Wi dth > LargeLogoInsert.Picture.He ight Then
Large_bestfit_ratio = 200 / LargeLogoInsert.Picture.Wi dth
Small_bestfit_ratio = 70 / SmallLogoInsert.Picture.Wi dth
Else
Large_bestfit_ratio = 95 / LargeLogoInsert.Picture.He ight
Small_bestfit_ratio = 44 / SmallLogoInsert.Picture.He ight
End If
'Resert Size
LargeLogoInsert.Width = LargeLogoInsert.Picture.Wi dth * Large_bestfit_ratio
LargeLogoInsert.Height = LargeLogoInsert.Picture.He ight * Large_bestfit_ratio
SmallLogoInsert.Width = SmallLogoInsert.Picture.Wi dth * Small_bestfit_ratio
SmallLogoInsert.Height = SmallLogoInsert.Picture.He ight * Small_bestfit_ratio
'Enter the Pictures Width/Height for Alteration
LargeLogoWidth = FormatNumber(LargeLogoInse rt.Picture .Width * Large_bestfit_ratio, 0)
LargeLogoHeight = FormatNumber(LargeLogoInse rt.Picture .Height * Large_bestfit_ratio, 0)
SmallLogoWidth = FormatNumber(SmallLogoInse rt.Picture .Width * Small_bestfit_ratio, 0)
SmallLogoHeight = FormatNumber(SmallLogoInse rt.Picture .Height * Small_bestfit_ratio, 0)
'Set Spinner buttons
With LargeLogoWidthSpinButton
.Max = LargeLogoWidth
.Min = 0
.Value = LargeLogoWidth
End With
With LargeLogoHeightSpinButton
.Max = LargeLogoHeight
.Min = 0
.Value = LargeLogoHeight
End With
With SmallLogoWidthSpinButton
.Max = SmallLogoWidth
.Min = 0
.Value = SmallLogoWidth
End With
With SmallLogoHeightSpinButton
.Max = SmallLogoHeight
.Min = 0
.Value = SmallLogoHeight
End With
Else
MsgBox ("Please Select a Valid Image File (*.JPG, *.JPEG, *.GIF)")
logo.Value = ""
End If
Else
MsgBox ("Please Enter a Valid Image File (*.JPG, *.JPEG, *.GIF)")
logo.Value = ""
End If
--
Thanks for your help all.
Jesse
--
'Org/Logo Options - Load Logos onto Form
Private Sub loadLogoButton_Click()
'Check to see if logo selected
If logo <> "" Then
'Check if valid File Type
FileType = Right(logo, 3)
If FileType = "jpg" Or FileType = "jpeg" Or FileType = "gif" Then
'Load picture onto form
LargeLogoInsert.PictureSiz
SmallLogoInsert.PictureSiz
LargeLogoInsert.Picture = LoadPicture(logo)
SmallLogoInsert.Picture = LoadPicture(logo)
'Set best Fit Picture Size
aspect_ratio = LargeLogoInsert.Picture.Wi
If LargeLogoInsert.Picture.Wi
Large_bestfit_ratio = 200 / LargeLogoInsert.Picture.Wi
Small_bestfit_ratio = 70 / SmallLogoInsert.Picture.Wi
Else
Large_bestfit_ratio = 95 / LargeLogoInsert.Picture.He
Small_bestfit_ratio = 44 / SmallLogoInsert.Picture.He
End If
'Resert Size
LargeLogoInsert.Width = LargeLogoInsert.Picture.Wi
LargeLogoInsert.Height = LargeLogoInsert.Picture.He
SmallLogoInsert.Width = SmallLogoInsert.Picture.Wi
SmallLogoInsert.Height = SmallLogoInsert.Picture.He
'Enter the Pictures Width/Height for Alteration
LargeLogoWidth = FormatNumber(LargeLogoInse
LargeLogoHeight = FormatNumber(LargeLogoInse
SmallLogoWidth = FormatNumber(SmallLogoInse
SmallLogoHeight = FormatNumber(SmallLogoInse
'Set Spinner buttons
With LargeLogoWidthSpinButton
.Max = LargeLogoWidth
.Min = 0
.Value = LargeLogoWidth
End With
With LargeLogoHeightSpinButton
.Max = LargeLogoHeight
.Min = 0
.Value = LargeLogoHeight
End With
With SmallLogoWidthSpinButton
.Max = SmallLogoWidth
.Min = 0
.Value = SmallLogoWidth
End With
With SmallLogoHeightSpinButton
.Max = SmallLogoHeight
.Min = 0
.Value = SmallLogoHeight
End With
Else
MsgBox ("Please Select a Valid Image File (*.JPG, *.JPEG, *.GIF)")
logo.Value = ""
End If
Else
MsgBox ("Please Enter a Valid Image File (*.JPG, *.JPEG, *.GIF)")
logo.Value = ""
End If
--
Thanks for your help all.
Jesse
groundwar:
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
and
LargeLogoInsert.Height