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. C#
  4. Print images with the correct size

Print images with the correct size

Scheduled Pinned Locked Moved C#
graphicshelptutorial
4 Posts 2 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.
  • E Offline
    E Offline
    Eagle32
    wrote on last edited by
    #1

    Hi, I am currently working on printing an image from my picturebox but i am finding difficulties regarding this. For example, I have a large image of 1024 x 768. How would i go about working out the correct size regarding the width and height so when the image is printed, it is printed with the original width and height i.e 1024 x 768 in this example. At the moment, i am having trouble doing this. If i do the following the image takes up all of the page(i know why) but the original image doesnt even take up the whole page. I am using A4 piece of paper. Here is the code:

    //the width and height I will be using
    float destHeight = bitmap.Height /bitmap.VerticalResolution * 90;
    float destWidth = bitmap.Width / bitmap.HorizontalResolution * 90;

    //Boundary for printable area
    float highestHeight = destHeight / e.MarginBounds.Height;
    float highestWidth = destWidth / e.MarginBounds.Width;

    I would greatly appreciate if somebody could kindly assist me with this problem. Thanks & Regards,

    A 1 Reply Last reply
    0
    • E Eagle32

      Hi, I am currently working on printing an image from my picturebox but i am finding difficulties regarding this. For example, I have a large image of 1024 x 768. How would i go about working out the correct size regarding the width and height so when the image is printed, it is printed with the original width and height i.e 1024 x 768 in this example. At the moment, i am having trouble doing this. If i do the following the image takes up all of the page(i know why) but the original image doesnt even take up the whole page. I am using A4 piece of paper. Here is the code:

      //the width and height I will be using
      float destHeight = bitmap.Height /bitmap.VerticalResolution * 90;
      float destWidth = bitmap.Width / bitmap.HorizontalResolution * 90;

      //Boundary for printable area
      float highestHeight = destHeight / e.MarginBounds.Height;
      float highestWidth = destWidth / e.MarginBounds.Width;

      I would greatly appreciate if somebody could kindly assist me with this problem. Thanks & Regards,

      A Offline
      A Offline
      Alan Balkany
      wrote on last edited by
      #2

      My guess: The vertical/horizontal resolution of the bitmap is not the same as the printer's resolution, so the destHeight/destWidth are getting incorrect values. You need to use the printer's resolution in your calculations.

      E 1 Reply Last reply
      0
      • A Alan Balkany

        My guess: The vertical/horizontal resolution of the bitmap is not the same as the printer's resolution, so the destHeight/destWidth are getting incorrect values. You need to use the printer's resolution in your calculations.

        E Offline
        E Offline
        Eagle32
        wrote on last edited by
        #3

        Hi, Thanks for replying. How would i go about doing this? Would this work? PrintDocument document = new PrintDocument(); document.PrinterSettings.DefaultPageSettings.PrinterResolution.X = 300; document.PrinterSettings.DefaultPageSettings.PrinterResolution.Y = 300; Thanks,

        A 1 Reply Last reply
        0
        • E Eagle32

          Hi, Thanks for replying. How would i go about doing this? Would this work? PrintDocument document = new PrintDocument(); document.PrinterSettings.DefaultPageSettings.PrinterResolution.X = 300; document.PrinterSettings.DefaultPageSettings.PrinterResolution.Y = 300; Thanks,

          A Offline
          A Offline
          Alan Balkany
          wrote on last edited by
          #4

          The printer's resolution would probably be mentioned in the owner's manual. If not, look on the manufacturer's web site. If it's not there, send their support department an email.

          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