?
Solved

VBA Picture Sizing

Posted on 2003-02-24
7
Medium Priority
?
974 Views
Last Modified: 2008-01-09
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.Width / LargeLogoInsert.Picture.Height
   large_bestfit_ratio = 200 / LargeLogoInsert.Picture.Width
   large_bestfit_size = large_bestfit_ratio * LargeLogoInsert.Picture.Width
   
     
   'Change Picture Size to Match Best Fit
   ???? = large_bestfit_size

end sub

--

Thanks in advanced for your help.
0
Comment
Question by:groundwar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 16

Expert Comment

by:twalgrave
ID: 8013711
LargeLogoInsert.Width
and
LargeLogoInsert.Height
0
 

Author Comment

by:groundwar
ID: 8014154
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.
0
 
LVL 9

Accepted Solution

by:
bhagyesht earned 200 total points
ID: 8014337
Simple way out would be to have an image control with the stretch property set to true and the following code

Image1.Picture = Picture1.Picture
picture1.visible=false

then set the height and width of image to suit your requirements.


---
I believe in KISS (keep it short and simple)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:twalgrave
ID: 8016880
Here's some code you will want to look at:
http://www.vb-helper.com/howto_fit_picture_to_box.html
0
 

Author Comment

by:groundwar
ID: 8017834
Adding -> LargeLogoInsert.PictureSizeMode = 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.PictureSizeMode = fmPictureSizeModeStretch
   SmallLogoInsert.PictureSizeMode = fmPictureSizeModeStretch
   LargeLogoInsert.Picture = LoadPicture(logo)
   SmallLogoInsert.Picture = LoadPicture(logo)

     
   'Set best Fit Picture Size
   aspect_ratio = LargeLogoInsert.Picture.Width / LargeLogoInsert.Picture.Height
   
   If LargeLogoInsert.Picture.Width > LargeLogoInsert.Picture.Height Then
    Large_bestfit_ratio = 200 / LargeLogoInsert.Picture.Width
    Small_bestfit_ratio = 70 / SmallLogoInsert.Picture.Width
   Else
    Large_bestfit_ratio = 95 / LargeLogoInsert.Picture.Height
    Small_bestfit_ratio = 44 / SmallLogoInsert.Picture.Height
   End If
   
   'Resert Size
    LargeLogoInsert.Width = LargeLogoInsert.Picture.Width * Large_bestfit_ratio
    LargeLogoInsert.Height = LargeLogoInsert.Picture.Height * Large_bestfit_ratio
    SmallLogoInsert.Width = SmallLogoInsert.Picture.Width * Small_bestfit_ratio
    SmallLogoInsert.Height = SmallLogoInsert.Picture.Height * Small_bestfit_ratio
     
   'Enter the Pictures Width/Height for Alteration
    LargeLogoWidth = FormatNumber(LargeLogoInsert.Picture.Width * Large_bestfit_ratio, 0)
    LargeLogoHeight = FormatNumber(LargeLogoInsert.Picture.Height * Large_bestfit_ratio, 0)
    SmallLogoWidth = FormatNumber(SmallLogoInsert.Picture.Width * Small_bestfit_ratio, 0)
    SmallLogoHeight = FormatNumber(SmallLogoInsert.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
0
 

Expert Comment

by:CleanupPing
ID: 9447536
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.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Simple Linear Regression
Introduction to Processes
Suggested Courses
Course of the Month8 days, 12 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question