-
Print and printpreview
Hi, I know this topic has been up several times, and I have searched different thread for several days without any sucess of solving my problem.
I have no problem with printing text, lines etc, but when it comes to a bitmap things get complicated for my small brain. ;)
The bitmap shows in the preview but I only get empty papers from the printer. Anyone know what I do wrong?
this is how my OnPrint looks like.
void CPrinttest1View::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
pDC->SetMapMode(MM_TWIPS);
CBitmap bmp;
bmp.LoadBitmap(IDB_BITMAP1);
CRect rectDraw(40,40,250,250);
CDC memDc;
memDc.CreateCompatibleDC(pDC);
CBitmap *pOldBmp = memDc.SelectObject(&bmp);
BITMAP bm;
bmp.GetBitmap(&bm);
CSize pBmpSize;
//A 'normal' copy, but it still needs a stretch because of the map mode
long nWidth = this->PointsToTwips(bm.bmWidth);
long nHeight = -this->PointsToTwips(bm.bmHeight);
POINT pos = this->PointsToTwips(rectDraw.left, rectDraw.top);
pDC->StretchBlt(pos.x, pos.y, nWidth, nHeight, &memDc, 0, 0,
bm.bmWidth, bm.bmHeight, SRCCOPY);
pBmpSize.cx = bm.bmWidth;
pBmpSize.cy = bm.bmHeight;
memDc.SelectObject(pOldBmp);
}
All help will be appretiated
thx
Anders Jansson
-
The problem is due to the printer DC not supporting the StretchBlt or BitBlt calls. It works OK in print preview because the preview DC is a screen DC which supports these calls.
If you want to print a bitmap, convert it to a DIB and use StretchDIBBits() to plot it. This should work for both screen/printer DC's.
-
ah, thx, any chance u have the code needed for the conversion?
thx alot
Anders
-
You should be able to find in the Bitmap section here or at CodeProject.
-
-
darn, I cant found much help on DIBs, anyone know how to convert to a DIB so I can use the StretchDIBlt function?
All help really appretiated, best would be if anyone have a few lines of code :)
/Anders
-
Ok, seems like I got most of it working now, so if anyone needs any help let me know and I'll try to help out.
Only problem I still have is printing very large images, it work for 7mbyte images but not for 15mbytes images, might be a printer problem though. Anyone know anything about that? Only getting blank papers.
/Anders
-
hello - I am having this same problem with printing bitmaps, and would really appreciate any sample code or links to sample code for getting this to work.
Thanks in advance,
Wade
-
I sent you some sample code hope it helps.
/Anders