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. Metafile problem...

Metafile problem...

Scheduled Pinned Locked Moved C#
helpgraphicsquestion
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'm coding a class to print barcodes. One of my methods is this: public Metafile GetMetafileImage() { PrinterSettings ps = new PrinterSettings(); Graphics g = ps.CreateMeasurementGraphics(); IntPtr pHdc = g.GetHdc(); Metafile 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.White; g.FillRectangle(b, 0, 0, whiteMarginWidth, height); float x = whiteMarginWidth; foreach (char ch in encodedValueString) { if (ch == '1') b = Brushes.Black; else b = Brushes.White; g.FillRectangle(b, x, 0, x + barSize, height); x += barSize; } b = Brushes.White; g.FillRectangle(b, x, 0, x + whiteMarginWidth, height); // <-- this g.Dispose(); return mf; } It works fine but the last FillRectangle operation. Its width isn't "whiteMarginWidth", but it's larger than "whiteMarginWidth". It seems to fill a rectangle whose wide reach the "end" of a region, perhaps a region set by the printer handle... I can't solve this problem :doh: Can you help me? Thank you! Luca

    S 1 Reply Last reply
    0
    • D devzav

      Hi all! I'm coding a class to print barcodes. One of my methods is this: public Metafile GetMetafileImage() { PrinterSettings ps = new PrinterSettings(); Graphics g = ps.CreateMeasurementGraphics(); IntPtr pHdc = g.GetHdc(); Metafile 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.White; g.FillRectangle(b, 0, 0, whiteMarginWidth, height); float x = whiteMarginWidth; foreach (char ch in encodedValueString) { if (ch == '1') b = Brushes.Black; else b = Brushes.White; g.FillRectangle(b, x, 0, x + barSize, height); x += barSize; } b = Brushes.White; g.FillRectangle(b, x, 0, x + whiteMarginWidth, height); // <-- this g.Dispose(); return mf; } It works fine but the last FillRectangle operation. Its width isn't "whiteMarginWidth", but it's larger than "whiteMarginWidth". It seems to fill a rectangle whose wide reach the "end" of a region, perhaps a region set by the printer handle... I can't solve this problem :doh: Can you help me? Thank you! Luca

      S Offline
      S Offline
      Skippums
      wrote on last edited by
      #2

      Change "x + whiteMarginWidth" to "whiteMarginWidth". That parameter is the width of the rectangle, NOT the right x-coordinate of the rectangle. -Jeff

      D 1 Reply Last reply
      0
      • S Skippums

        Change "x + whiteMarginWidth" to "whiteMarginWidth". That parameter is the width of the rectangle, NOT the right x-coordinate of the rectangle. -Jeff

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

        Great! I was wrong in considering it as the right x-coordinate of the rectangle! Thank you very much Jeff :-D

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

        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