Solved

Scale JPG to fill Picture box

Posted on 2002-06-06
5
441 Views
Last Modified: 2013-11-22
I want to print a form. The form has 2 picture boxes and a scale bar.

On the form load I set one picture box to point to a bmp, and the other to point to a jpg.

The jpg is of variable dimensions. (It is a map. The maps size is dependant on the parents window size.)

anyhow - the idea is I want to have the picture box as a fixed size, and then scale the pictures to fit them.

Cheers,

woot.

0
Comment
Question by:woottond
5 Comments
 
LVL 4

Expert Comment

by:TomLaw1999
ID: 7060055
Have you considered using an image instead of a picture box.
0
 
LVL 2

Accepted Solution

by:
vbDoc earned 100 total points
ID: 7060200
Here you go .. ..
Inputs:  Filepath (The path of the image to load)
Returns: None
Assumes: Create a new form (in my example: frmMain), Place a picturebox control on that form, name it picStart. Set picStart.Autosize to TRUE. Set picStart.Visible to FALSE. Create another picturebox on the form called picMain. This will be the picturebox that determins the final size of your image. Set picMain.Autosize to False. Create an Image Object *INSIDE* the picturebox control. Name the image control imgMain. Set ingMain.Stretch to TRUE.
Side Effects: NONE
***************************************************
Private Sub LoadImage(filePath As String)
    Dim X As Long
    Dim Y As Long
    With frmMain
        .imgMain.Visible = False
        .picStart.Picture = LoadPicture(filePath)
        X = .picStart.Width
        Y = .picStart.Height
        If X > .picMain.Width Then
             X = .picMain.Width
        End If '»If X > .picMain.Width Then
        If Y > .picMain.Height Then
             Y = .picMain.Height
        End If '»If Y > .picMain.Height Then
        .imgMain.Width = X
        .imgMain.Height = Y
        ' *** center the picture
        .imgMain.Top = (.picMain.Height \ 2) - (.imgMain.Height \ 2)
        .imgMain.Left = (.picMain.Width \ 2) - (.imgMain.Width \ 2)

        ' *** now copy the image from the start picbox(picstart) into the
        '     display image field (imgMain)
        .imgMain.Picture = .picStart.Picture
        .imgMain.Visible = True
    End With '»With frmMain
End Sub
*********************************************
Regards, John vb_doc@hotmail.com
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 7060352
Imagebox would be my first choice, too.

Otherwise, you can use the PaintPicture method of the Picturebox to scale the picture to the desired size.
0
 

Author Comment

by:woottond
ID: 7062057
Thank you to both of you.

I had not noticed the Image object.

I created a Picture Box and put the image in it. Problem solved.

I didn't have to use vbDoc's code but I used the image in picbox they said.

I did use a image as TomLaw1999 said...

so points for both sound fair??
0
 

Author Comment

by:woottond
ID: 7062062
Thank you vbDoc AND TomLaw1999

cheers,

woot.
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

Suggested Solutions

Title # Comments Views Activity
Copy a row 12 57
TT Auto Dashboard 13 83
CheckListBox usage 3 50
VB 6 error 5 in windows 10 but not in XP 7 44
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…

910 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

23 Experts available now in Live!

Get 1:1 Help Now