Solved

resize picturebox picture

Posted on 2000-04-22
7
329 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
  • 4
  • 2
7 Comments
 
LVL 1

Expert Comment

by:plasmatek
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 32

Expert Comment

by:Erick37
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
he realy knows his stuff.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now