auto resizing of a picture or image box

smiler44

Registered User.
Local time
Today, 03:35
Joined
Jul 15, 2008
Messages
690
I have a number of jpeg pictures. the user can choose anyone to load in to the picture or image box. I'm not to sure which to use. i'm using VB version 5

The pictures are all different sizes. I can get them to load into a picture box and have the picture box change to the right size to accomidate the picture but this can be bigger then i want it to go to.
I would like to load the picture into a picture or image box and allow the picture or image box to resize to accomidate the picture but upto a size of 4 inches by 4 inches, some pictures may be 4 inches wide and only 3 high so the picture or image box has to resize to this size. At this point the bigger pictures would have to reduce in size to fit into the picture or image box, how do i do this and keep the height/width ratio the same for the new size image as it is for the original?

At the moment i am manually resizing the pictures and saving them but this is not ideal as the pictures are to be updated

thank you in advance

smiler44
 
I have got this sussed and will post the code another night when i have access to it.

smiler44
 
This is how i solved my problem.
The strech property of the image box is set to true
I assigned a picture to the image box via the picture property of the image box

Code:
Private Sub Form_Load()
'1440 twips to an inch
Dim aratio As String ' aspect ratio
 
aratio = (Image1.Width) / (Image1.Height) ' gets aspect ratio

' the do loop makes pictures go to a size of less then
' 5 inches wide
Do Until Image1.Width < 7200 'twips
If Image1.Width > 7199 Then
Image1.Width = Image1.Width - 1440
End If
Image1.Height = (Image1.Width / aratio) 'this maintains the original aspect ratio
Loop
 
Form1.Width = Image1.Width + 140 'this allows for form side borders
Form1.Height = Image1.Height + 520 ' this allows fof top and bottom borders
End Sub
 

Users who are viewing this thread

Back
Top Bottom