|
-
January 28th, 2012, 02:35 PM
#6
Re: Unable to implement DIB printing with GDI (MFC)
Well, update:
Microsoft's documentation about StretchDIBits is totally wrong. I found out that direction of Y axis has to be changed. Now following code works:
PHP Code:
// Copy back buffer to screen dc:
pDC->SetStretchBltMode(HALFTONE);
SetBrushOrgEx(pDC->GetSafeHdc(), 0, 0, 0);
HBITMAP hMemBitmap = (HBITMAP)_pMemDc->SelectObject(_hOldSelBitmap);
DWORD dwLines = StretchDIBits(pDC->GetSafeHdc(),
rectClipBoxPlayground.left, rectClipBoxPlayground.top, rectClipBoxPlayground.Width(), rectClipBoxPlayground.Height(),
rectClipBoxBackBuffer.left, _sizeBackBuffer.cy - rectClipBoxBackBuffer.top - rectClipBoxBackBuffer.Height(), rectClipBoxBackBuffer.Width(), rectClipBoxBackBuffer.Height(),
_pBitmapRawBits, &_bitmapInfo, DIB_RGB_COLORS, SRCCOPY);
_pMemDc->SelectObject(hMemBitmap);
BUT... It does not print on physical printers! Let me start from beginning: In the beginning I used StretchBlt, which worked well for screen drawing, print preview, and printing on virtual (pdf) printers. But it was not working on actual printers. Then I tried to change my code to use StretchDIBits but I was failing until now. As I'm posting this now, I found the solution for StretchDIBits so that it works well for screen drawing and print preview, but oddly, it still is not working for actual printing, just like StretchBlt!
By "not working" I mean the following: it returns success code, but draws incorrect parts of the image buffer: sometimes it prints first few pages repeatedly (not matter what pages I select), sometimes it prints black pages. The strangest thing here is that print preview is working like it should! So if I had messed up coordinate calculation (like one would suspect seeing the results), print preview should be failing as well.
More info:
I have a large backbuffer, one big DIB, say 5000x3000. I divide this to pages, say 4 pages a row, 3 rows - 12 pages in total. Now when I print only 2nd page, it prints well. When I print 5th page only, it prints all black page. When I print, say, 6th page only, it prints 2nd page. And when I select to print whole range (1-12) it repeatedly prints first four pages - the pages that are in first row. I don't know if there is any coincidence, or there is any pattern. Again, anyone would suspect that I calculate page coordinates incorrectly, but how the hell is print preview always working fine!
StretchBlt and now StretchDIBits both fail. Now I tried stretching to another memory bitmap, and then using BitBlt and it succeeded - all pages print like they should. But due to two blitting operations for each page, process is slow (this is noticeable on print preview). Plus additional buffer is required which increases memory consumption. I'd like to avoid this. But I can't get either of StretchBlt and StretchDIBits to print!
Help!
Tags for this Thread
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
|