Scale / Resize Graphics While Printing
Posted: 2002-06-01
By: ArchiveBot
Viewed: 127
Filed Under:
No attachments for this post
To print images stored in any random sizes within the specified Height and Width.
Without selecting and applying the proper "ScaleFactor" the images tend to get distorted - squashed or stretched - when they are resized to be printed on the form, picture box or the printer object.
The code below will ensure that the image is not distorted nor croped at the time of printing.
Original Author: Gajendra S. Dhir
Code
Step 1: Initialize and Get the Image
Dim Photo as StdPicture
Set Photo = LoadPicture("Photo.jpg")
Step 2: Set Output Size
MaxHeight = 1400 '1.00 inch
MaxWidth = 1050 '0.75 inch
Step 3: Determine the Scale Factor
'The dimensions of the image file
picHeight = Photo.Height
picWidth = Photo.Width
If picHeight > picWidth Then
'if height is more than width
'get Scale factor based on height sFactor = MaxHeight / picHeight
Else
'if height is less than width
'get Scale factor based on height sFactor = MaxWidth / picWidth
End If
Step 4: The final paint command
printer.PaintPicture Photo, StartLeft, StartTop, picWidth * sFactor, picHeight * sFactor
Replace the printer
with the name of the form or picture box are required if you want to display the image on the screen.
Here's the complete code.
Dim Photo as StdPicture
Set Photo = LoadPicture("Photo.jpg")picHeight = Photo.Height
picWidth = Photo.Width
If picHeight > picWidth Then
'if height is more than width
'get Scale factor based on height sFactor = MaxHeight / picHeight
Else
'if height is less than width
'get Scale factor based on height sFactor = MaxWidth / picWidth
End If
Printer.PaintPicture Photo, StartLeft, StartTop, picWidth * sFactor, picHeight * sFactor
Comments on this post
No comments have been added for this post.
You must be logged in to make a comment.