Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reducing pictures to fit the screen.

Status
Not open for further replies.

jjhobs

Instructor
Sep 18, 2003
27
GB
Some time ago I wrote a program which loaded photos into a picturebox. Nowadays digital photos are much larger and are often too big for the screen. Does anyone know of code which will check the size of the picturebox against the size of the screen, and automatically reduce the picturebox if it is too large, say by 60%, 50% or whatever is necessary to fit it to the screen?
 

You can use the screen.width/screen.height versus the picture1.width/picture1.height for a comparison if you wish or you can...
[tt]
Dim P As Picture

Set P = LoadPicture("F:\z\01.jpg")
[/tt]
and then use P.Width/P.Height. Then if the picture is greater than the screen display area you can use an image control instead of a picture box with it's strech property set to true.

Good Luck


 
Thanks for this. You are quite right an image control works very well. However, I want to then be able to use the pset and point methods which are not available with an image. Do you have any other ideas?
 
You might try putting the image control inside the picture control. First resize the picture control to fit the screen, then resize the image to fit the picture control.

Just an idea..
good luck, Wayne
 
Wayne
This sounds good - I hadn't thought of anything like it. However, I am slightly confused. Do I load the picture into the picture or the image control? If I load it into the picture control which has been sized to the screen, the image is still too big for the picture. Do this make sense? Any help would be appreciated.
 
You would put your picture into the Image control. The stretch property of that control needs to be set to true, so the picture would resize itself to the Image control's size.

What were you using the Picture Controls's pset functions for? If you were altering the picture, (painting), then my idea will not work for you.
 

Ok... give this a try. You will need a picture box and an image box (picture1 and image1) for this example.
[tt]
Option Explicit

Private Sub Form_Load()

Dim P As Picture

Me.Height = 5000
Me.Width = 8000

With Picture1
.Width = 3000
.Height = 3000
.Left = 200
.Top = 200
End With

With Image1
.Width = 3000
.Height = 3000
.Left = 4000
.Top = 200
.Stretch = True
End With

Set P = LoadPicture("E:\funstuff\pictures\clouds.bmp")

Image1.Picture = P

If P.Height > Picture1.Height Then

Picture1.PaintPicture P, 0, 0, Picture1.Width, Picture1.Height

Else

Picture1.Picture = P

End If

End Sub
[/tt]

Now I would suggest that you use some sort of aspect ratio to figure out the height vs width so your picture does not look like it has been stretch too far in one aspect vs the other.

Also you may want to check the width also...

Good Luck

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top