Printing PNG file or any image file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Wondering if it is possible to send a xxx.PNG file directly to a printer without having to load it into a windows form, picturebox, ect... If so how do you do it

Thanks in advance
Kent
 
* "=?Utf-8?B?S2VudA==?= said:
Wondering if it is possible to send a xxx.PNG file directly to a
printer without having to load it into a windows form, picturebox,
ect... If so how do you do it?

See 'PrintDocument' class, its 'PrintPage' event. There you can simply
use code like this:

\\\
Dim bmp As Image = Image.FromFile(...)
e.Graphics.DrawImage(bmp, ...)
bmp.Dispose()
///
 
Hi,

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
PrintDocument1.Print()
End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object,
ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles
PrintDocument1.PrintPage
Dim g As Graphics = e.Graphics

g.DrawImage(Image.FromFile("C:\camera.bmp"), 5, 5)
End Sub

Ken
 
Thanks everyone for suggestions. This is what I came up with. Although the e.graphics.FromImage throws an exception it does still print to my printer.

The exception is: "a graphics object cannot be created from an image that has an indexed pixel format

As you can see I'm not handling the exception, any suggestions would be greatly appreciated

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Clic
PrintDocument1.Print(
End Su

Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPag
Dim objObject As Objec
Dim objBMP As Bitma

Tr
' Load the image
objObject = Image.FromFile("C:\xmltest\Label.png"
objBMP = objObject.Clon

Dim myimage = objBMP.Clon

e.Graphics.FromImage(myimage) <--Exception thrown her
Catch ex As Exceptio

Finall
e.Graphics.Dispose(
objObject.dispose(
objObject = Nothin
End Tr

End Su

Thanks again
Kent
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top