Printing bitmaps to printer
-
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?
-
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?
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++