Solved

resize picturebox picture

Posted on 2000-04-22
7
340 Views
Last Modified: 2011-10-03
i am using vb5, and i made a quick browsing and text editing tool.  i expanded it to graphics, but the go off the form.  how do resize the graphic, to stay proportionate, but to fit in the space allocated for them?
0
Comment
Question by:blackc
[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
  • 4
  • 2
7 Comments
 
LVL 1

Expert Comment

by:plasmatek
ID: 2739807
Use an imagebox instead of a picturebox and set image1.stretch to true.

Accept comment as answer if this helps.
0
 

Author Comment

by:blackc
ID: 2739952
thanx anyway, but i already did that, and it distorts the pictures so bad it isn't even funny.  i need to just be able to adjust one length (the longer one) and then that lenght will be entirely inside the available area, and so the shorter side must be 2.  i need to keep it proportional.
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 50 total points
ID: 2740284
This example stretches an image into a picturebox, retaining the aspect ratio of the original picture:

Option Explicit

Private Sub Command1_Click()
    On Error Resume Next
    Dim dx As Long, dy As Long
    Dim sngAspectPic As Single
    Dim pic As StdPicture
    Set pic = LoadPicture("c:\test2.bmp")
    If Not (pic Is Nothing) Then
        Picture1.AutoRedraw = True
        'get image dimensions
        dx = ScaleX(pic.Width, vbHimetric, Picture1.ScaleMode)
        dy = ScaleY(pic.Height, vbHimetric, Picture1.ScaleMode)
        'Get aspect ratio of picture (h/w)
        sngAspectPic = pic.Height / pic.Width
        'Determine if width or height should fill the PictureBox
        If (sngAspectPic > (Picture1.Height / Picture1.Width)) Then
            Picture1.PaintPicture pic, 0, 0, Picture1.Height / sngAspectPic, Picture1.Height
        Else
            Picture1.PaintPicture pic, 0, 0, Picture1.Width, Picture1.Width * sngAspectPic
        End If
    End If
    'Set the picture = to the new image
    Picture1.Picture = Picture1.Image
    Picture1.AutoRedraw = False
    'Clear the old picture
    Set pic = LoadPicture("")
End Sub
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 32

Expert Comment

by:Erick37
ID: 2740294
Some modifications; change

Picture1.Height to
Picture1.Scaleheight

and

Picture1.Width to
Picture1.Scalewidth

in the above code, all occurances.
0
 

Author Comment

by:blackc
ID: 2741630
erick37, i don't know if it works or not because w/ the option explicit in the general declerations, it now has a problem w/ nearly every other variable in my program.  since i am dealing with file paths a lot, there are quite a few variables.  how would i adjust your code or mine so taht they would work together?  i can send you my program, but if you changed anything, i would appreciate a commented explanation of why you canged each thing.  in a test project i did, your code worked beautifully.  now we just need to merge the code.
0
 

Author Comment

by:blackc
ID: 2741686
sorry bout that, i just took a closer look at your code, and realized(feeling pretty stupid afterwards) that all i had to do was to remove teh option explicit and replace (C:\test2.bmp)  with the variable for the file user has selected.  so now it works great!  thanx a lot!
0
 

Author Comment

by:blackc
ID: 2741692
he realy knows his stuff.
0

Featured Post

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!

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

717 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