Solved

Scale JPG to fill Picture box

Posted on 2002-06-06
5
442 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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…

777 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