I used this function, note that it uses the PaintPicture method. This function prints the image to a full page size. The picture is stored in a Picture Box control (you can remove the sound/wav part of the code as it calls a sound api routine):
Public Sub PrintPictureToFitPage(Pic As Picture)
Dim PicRatio As Double
Dim printerWidth As Double
Dim printerHeight As Double
Dim printerRatio As Double
Dim printerPicWidth As Double
Dim printerPicHeight As Double
' Determine if picture should be printed in landscape or portrait
' and set the orientation.
If Pic.height >= Pic.width Then
Printer.Orientation = vbPRORPortrait ' Taller than wide.
Else
Printer.Orientation = vbPRORLandscape ' Wider than tall.
End If
' Calculate device independent Width-to-Height ratio for picture.
PicRatio = Pic.width / Pic.height
' Calculate the dimentions of the printable area in HiMetric.
printerWidth = Printer.ScaleX(Printer.ScaleWidth, Printer.ScaleMode, vbHimetric)
printerHeight = Printer.ScaleY(Printer.ScaleHeight, Printer.ScaleMode, vbHimetric)
' Calculate device independent Width to Height ratio for printer.
printerRatio = printerWidth / printerHeight
' Scale the output to the printable area.
If PicRatio >= printerRatio Then
' Scale picture to fit full width of printable area.
printerPicWidth = Printer.ScaleX(printerWidth, vbHimetric, Printer.ScaleMode)
printerPicHeight = Printer.ScaleY(printerWidth / PicRatio, vbHimetric, Printer.ScaleMode)
Else
' Scale picture to fit full height of printable area.
printerPicHeight = Printer.ScaleY(printerHeight, vbHimetric, Printer.ScaleMode)
printerPicWidth = Printer.ScaleX(printerHeight * PicRatio, vbHimetric, Printer.ScaleMode)
End If
' Print the picture using the PaintPicture method.
Printer.PaintPicture Pic, 0, 0, printerPicWidth, printerPicHeight
Dim w As Integer
w = waveOutGetNumDevs()
If w > 0 Then
sndPlaySound "c:\police\output_3.wav", 1
Else
'MsgBox "Your system can not play sound files."
End If
End Sub
I used paintpicture to print a graphic, but the code was not nearly so detailed. What is the difference in the output of your method
PicRatio = Pic.width / Pic.height
' Calculate the dimentions of the printable area in HiMetric.
printerWidth = Printer.ScaleX(Printer.ScaleWidth, Printer.ScaleMode,
vbHimetric)
printerHeight = Printer.ScaleY(Printer.ScaleHeight,
Printer.ScaleMode, vbHimetric)
' Calculate device independent Width to Height ratio for printer.
printerRatio = printerWidth / printerHeight
' Scale the output to the printable area.
If PicRatio >= printerRatio Then
' Scale picture to fit full width of printable area.
printerPicWidth = Printer.ScaleX(printerWidth, vbHimetric,
Printer.ScaleMode)
printerPicHeight = Printer.ScaleY(printerWidth / PicRatio,
vbHimetric, Printer.ScaleMode)
Else
' Scale picture to fit full height of printable area.
printerPicHeight = Printer.ScaleY(printerHeight, vbHimetric,
Printer.ScaleMode)
printerPicWidth = Printer.ScaleX(printerHeight * PicRatio,
vbHimetric, Printer.ScaleMode)
End If
' Print the picture using the PaintPicture method.
Printer.PaintPicture Pic, 0, 0, printerPicWidth, printerPicHeight
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.