Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Scale JPG to fill Picture box

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

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…
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…
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…

860 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