Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Printing a bitmap

Printing a bitmap

Scheduled Pinned Locked Moved Visual Basic
csharpgraphicsworkspace
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Robert Gronenthal
    wrote on last edited by
    #1

    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

    D S 2 Replies Last reply
    0
    • R Robert Gronenthal

      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

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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 names

      Dim 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 Sub

      Warning: 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

      R 1 Reply Last reply
      0
      • D Dave Kreskowiak

        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 names

        Dim 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 Sub

        Warning: 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

        R Offline
        R Offline
        Robert Gronenthal
        wrote on last edited by
        #3

        Dave, Do I have to add the reference object in order to get these properties to work? Thanks, Bob

        D 1 Reply Last reply
        0
        • R Robert Gronenthal

          Dave, Do I have to add the reference object in order to get these properties to work? Thanks, Bob

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • R Robert Gronenthal

            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

            S Offline
            S Offline
            superprogrammingdude
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups