Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

resize picturebox picture

Posted on 2000-04-22
7
Medium Priority
?
344 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 200 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

610 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