Scale / Resize Graphics While Printing
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.
Rate Scale / Resize Graphics While Printing
(2(2 Vote))
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
Scale / Resize Graphics While Printing Comments
No comments yet — be the first to post one!
Post a Comment