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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing a graphic

Status
Not open for further replies.

DeliRick

Programmer
Apr 28, 2002
5
US
I want to print a logo (logo.jpg) on the top of the page. How do I do this?
 
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 want to design a Multimetre teaching tool using vb. how to measure voltage current and resistance..
 
normanx1

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

and the method I used?

Printer.PaintPicture Pic, 0, 0,Printer.Width, Printer.Height

t.smith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top