Solved

Scale JPG to fill Picture box

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

708 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

16 Experts available now in Live!

Get 1:1 Help Now