-
June 27th, 2002, 07:45 AM
#1
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
-
June 27th, 2002, 08:48 AM
#2
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.
Please use meaningful question titles - "Help me" does not let me know whether I can help with your question, and I am unlikely to bother reading it.
Please remember to rate useful answers. It lets us know when a question has been answered.
-
June 27th, 2002, 08:51 AM
#3
ah, thx, any chance u have the code needed for the conversion?
thx alot
Anders
-
June 27th, 2002, 08:53 AM
#4
You should be able to find in the Bitmap section here or at CodeProject.
Please use meaningful question titles - "Help me" does not let me know whether I can help with your question, and I am unlikely to bother reading it.
Please remember to rate useful answers. It lets us know when a question has been answered.
-
June 27th, 2002, 08:55 AM
#5
-
June 28th, 2002, 02:31 AM
#6
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
-
July 8th, 2002, 06:53 AM
#7
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
-
September 26th, 2002, 03:15 PM
#8
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
-
September 27th, 2002, 09:31 AM
#9
I sent you some sample code hope it helps.
/Anders
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|