Printing a bitmap
-
I have a vb.net program that writes a bitmap image to a file.. IE: C:\map\map.bmp I want to take that file and print it to a specific printer or multiple printers that is not the default printer in the printer menu. I do not want this to be interactive but automatic. Basically the program is a mapping application and I want a copy of the map to automatically print when the address is located. This is for a fire dispatching environment. Bob
-
I have a vb.net program that writes a bitmap image to a file.. IE: C:\map\map.bmp I want to take that file and print it to a specific printer or multiple printers that is not the default printer in the printer menu. I do not want this to be interactive but automatic. Basically the program is a mapping application and I want a copy of the map to automatically print when the address is located. This is for a fire dispatching environment. Bob
You would ahve to load the
C:\map\map.bmp
file into a Bitmap object. Easy enough:Dim mapImage As New Bitmap(filepath)
Then you would have to get the list of printers installed on the machine using the
PrinterSettings
object. There is a static member that returns a string array of all the printer namesDim printNames As String = PrinterSettings.InstalledPrinters
From there you would loop through the list of list of installed printers and print your Bitmap object to each one:
Dim printer As String
For Each printer In printNames
Dim pd As New PrintDocument
AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage
pd.Print()
Next
Private Sub pd_PrintPage(sender As Object, ev As PrintPageEventArgs)
Dim leftMargin As Single = ev.MarginBounds.Left
Dim topMargin As Single = ev.MarginBounds.Top
ev.Graphics.DrawImageUnscaled(mapImage, leftMargin, topMargin)
ev.HasMorePages = False
End SubWarning: This code is untested. I wrote it from memory without the aid of the IDE, so there will WILL be bugs in it! :-D RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
You would ahve to load the
C:\map\map.bmp
file into a Bitmap object. Easy enough:Dim mapImage As New Bitmap(filepath)
Then you would have to get the list of printers installed on the machine using the
PrinterSettings
object. There is a static member that returns a string array of all the printer namesDim printNames As String = PrinterSettings.InstalledPrinters
From there you would loop through the list of list of installed printers and print your Bitmap object to each one:
Dim printer As String
For Each printer In printNames
Dim pd As New PrintDocument
AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage
pd.Print()
Next
Private Sub pd_PrintPage(sender As Object, ev As PrintPageEventArgs)
Dim leftMargin As Single = ev.MarginBounds.Left
Dim topMargin As Single = ev.MarginBounds.Top
ev.Graphics.DrawImageUnscaled(mapImage, leftMargin, topMargin)
ev.HasMorePages = False
End SubWarning: This code is untested. I wrote it from memory without the aid of the IDE, so there will WILL be bugs in it! :-D RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
Dave, Do I have to add the reference object in order to get these properties to work? Thanks, Bob
-
Dave, Do I have to add the reference object in order to get these properties to work? Thanks, Bob
Be sure your including this at the top of your code
Imports System.Drawing.Printing
No references need to be set. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
I have a vb.net program that writes a bitmap image to a file.. IE: C:\map\map.bmp I want to take that file and print it to a specific printer or multiple printers that is not the default printer in the printer menu. I do not want this to be interactive but automatic. Basically the program is a mapping application and I want a copy of the map to automatically print when the address is located. This is for a fire dispatching environment. Bob
Bob, (I am taking a stab at it, I'm not 100% sure, but it douen't hurt to try.) I don't know how you are trying to print, but you should loop through the procedure with a FOR -> NEXT loop. This will allow you to enter in the amount of time you want to print. In the loop be sure to increase the variable by 1.