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. Printing a rectangle with exact sizes...

Printing a rectangle with exact sizes...

Scheduled Pinned Locked Moved C#
graphicshelpquestion
3 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.
  • D Offline
    D Offline
    devzav
    wrote on last edited by
    #1

    Hi all! I have to print a bar with its exact sizes. I used this code to generate a bar: PrinterSettings ps = new PrinterSettings(); Graphics g = ps.CreateMeasurementGraphics(); IntPtr pHdc = g.GetHdc(); mf = new Metafile(pHdc, EmfType.EmfOnly); g.ReleaseHdc(pHdc); g.Dispose(); g = Graphics.FromImage(mf); g.PageUnit = GraphicsUnit.Millimeter; g.PageScale = 1; Brush b = Brushes.Black; g.FillRectangle(b, 0, 0, 2, 30); float dpix = g.DpiX; float dpiy = g.DpiY; g.Dispose(); Bitmap bm = new Bitmap(mf, (int)(mf.Width / mf.HorizontalResolution * dpix), (int)(mf.Height / mf.VerticalResolution * dpiy)); mf.Dispose(); Well, when I print the bm Bitmap I obtain a big bar on my page: it isn't 2x30 mm wide, but 12x188 mm wide! Can you help me? Thanks in advantage

    A 1 Reply Last reply
    0
    • D devzav

      Hi all! I have to print a bar with its exact sizes. I used this code to generate a bar: PrinterSettings ps = new PrinterSettings(); Graphics g = ps.CreateMeasurementGraphics(); IntPtr pHdc = g.GetHdc(); mf = new Metafile(pHdc, EmfType.EmfOnly); g.ReleaseHdc(pHdc); g.Dispose(); g = Graphics.FromImage(mf); g.PageUnit = GraphicsUnit.Millimeter; g.PageScale = 1; Brush b = Brushes.Black; g.FillRectangle(b, 0, 0, 2, 30); float dpix = g.DpiX; float dpiy = g.DpiY; g.Dispose(); Bitmap bm = new Bitmap(mf, (int)(mf.Width / mf.HorizontalResolution * dpix), (int)(mf.Height / mf.VerticalResolution * dpiy)); mf.Dispose(); Well, when I print the bm Bitmap I obtain a big bar on my page: it isn't 2x30 mm wide, but 12x188 mm wide! Can you help me? Thanks in advantage

      A Offline
      A Offline
      Adeel Chaudhry
      wrote on last edited by
      #2

      Hi, "mm" is not the standard for computers! Neither for the postscript i guess. Secondly, it differs for different disply resolution. For Example: Screen Res: 1024x768, Diagonal Size: 19", Pixel size: 0.377mm Screen Res: 800x600, Diagonal Size: 17", Pixel size: 0.4318mm Screen Res: 640x480, Diagonal Size: 15", Pixel size: 0.4763mm (taken from ^ [^]) So you better calculate about your display resolution. Hope that helps! Regards, Adeel

      Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.

      D 1 Reply Last reply
      0
      • A Adeel Chaudhry

        Hi, "mm" is not the standard for computers! Neither for the postscript i guess. Secondly, it differs for different disply resolution. For Example: Screen Res: 1024x768, Diagonal Size: 19", Pixel size: 0.377mm Screen Res: 800x600, Diagonal Size: 17", Pixel size: 0.4318mm Screen Res: 640x480, Diagonal Size: 15", Pixel size: 0.4763mm (taken from ^ [^]) So you better calculate about your display resolution. Hope that helps! Regards, Adeel

        Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.

        D Offline
        D Offline
        devzav
        wrote on last edited by
        #3

        Hi, thanks for your answare. The problem is that I don't want to draw the bar on screen, but I have to print it on my printer. Pehraps I can solve the problem using the printer resolution (600 dpi in my case). Thanks again!

        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