Solved

resize picturebox picture

Posted on 2000-04-22
7
333 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

920 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

18 Experts available now in Live!

Get 1:1 Help Now