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 / C++ / MFC
  4. Printing bitmaps to printer

Printing bitmaps to printer

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsquestion
2 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.
  • S Offline
    S Offline
    Santanu Lahiri
    wrote on last edited by
    #1

    I have a series of small bitmaps I need to print. The bitmaps are approx. 20 pixels wide and 15 pixels high. I would like them to print on the printer at about 1/4" or so high and 3/4" wide. I figured I could use the StretchBlt call to do this. I am using the following code: // nTxtHt holds the height of a line of text to be printed

    CBitmap bmp;
    bmp.LoadBitmap (nBmpID);

    BITMAP bm;
    bmp.GetBitmap (&bm);

    int nWd = bm.bmWidth;
    int nHt = bm.bmHeight;
    int nWide = MulDiv (nWd, nTxtHt, nHt);

    CDC memDC;
    memDC.CreateCompatibleDC (pDC);
    CBitmap *pBmpOld = memDC.SelectObject (&bmp);

    CRect rc (CPoint (nX, nY), CSize (nWide, nTxtHt));
    pDC->Rectangle (&rc);
    pDC->StretchBlt(nX, nY, nWide, nTxtHt, &memDC, 0, 0, nWd, nHt, SRCCOPY);
    memDC.SelectObject(pBmpOld);

    The framing rectangle prints just fine. The bitmap prints fine in preview. But when printed to printer, it shows up as a dot. What am I doing wrong here?

    C 1 Reply Last reply
    0
    • S Santanu Lahiri

      I have a series of small bitmaps I need to print. The bitmaps are approx. 20 pixels wide and 15 pixels high. I would like them to print on the printer at about 1/4" or so high and 3/4" wide. I figured I could use the StretchBlt call to do this. I am using the following code: // nTxtHt holds the height of a line of text to be printed

      CBitmap bmp;
      bmp.LoadBitmap (nBmpID);

      BITMAP bm;
      bmp.GetBitmap (&bm);

      int nWd = bm.bmWidth;
      int nHt = bm.bmHeight;
      int nWide = MulDiv (nWd, nTxtHt, nHt);

      CDC memDC;
      memDC.CreateCompatibleDC (pDC);
      CBitmap *pBmpOld = memDC.SelectObject (&bmp);

      CRect rc (CPoint (nX, nY), CSize (nWide, nTxtHt));
      pDC->Rectangle (&rc);
      pDC->StretchBlt(nX, nY, nWide, nTxtHt, &memDC, 0, 0, nWd, nHt, SRCCOPY);
      memDC.SelectObject(pBmpOld);

      The framing rectangle prints just fine. The bitmap prints fine in preview. But when printed to printer, it shows up as a dot. What am I doing wrong here?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      If your printer is 300 DPI, then a 300x300 bitmap will by one inch by one inch. So you need to work out the size of the printer DC, then you can work out how big you need to stretchblt the bitmap. Christian Graus - Microsoft MVP - C++

      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