?
Solved

Scale JPG to fill Picture box

Posted on 2002-06-06
5
Medium Priority
?
446 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
[X]
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
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 400 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

752 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