Solved

Print bitmap in OnPrint()

Posted on 1998-01-13
6
382 Views
Last Modified: 2013-11-20
I'm drawing some bitmaps in my document's view. It draws properly in print preview (OnPrint method), but then it doesn't print on the paper.
Any ideas?
0
Comment
Question by:jurasz
  • 3
  • 3
6 Comments
 
LVL 7

Expert Comment

by:galkin
ID: 1313977
Could you provide your printing code?
0
 

Author Comment

by:jurasz
ID: 1313978
This is a piece of OnPrint method. I'm using MM_TWIPS to position the bitmap (RECT r)
. . .
if(LoadBMPImage(bmpFileName, bitmap, NULL))
      {
            // Create a compatible memory DC
            CDC memDC;
            memDC.CreateCompatibleDC( pDC );
            memDC.SetMapMode(MM_TEXT);
            memDC.SelectObject( &bitmap );


            CDC sysDC;
            sysDC.CreateCompatibleDC(NULL);
            sysDC.SetMapMode(MM_TEXT);
            int srat_x = sysDC.GetDeviceCaps(LOGPIXELSX);
            int srat_y = sysDC.GetDeviceCaps(LOGPIXELSY);


            BITMAP bm;
            bitmap.GetBitmap( &bm );
            SIZE sz, szr;
            sz.cx = r.left;
            sz.cy = -r.top;
            szr.cx = r.right - r.left;
            szr.cy = abs(r.bottom - r.top);


            pDC->LPtoDP(&sz);
            pDC->LPtoDP(&szr);
            CSize size2;
            int rat_x = pDC->GetDeviceCaps(LOGPIXELSX);
            int rat_y = pDC->GetDeviceCaps(LOGPIXELSY);
            size2.cx = bm.bmWidth * rat_x / srat_x;
            size2.cy = bm.bmHeight * rat_y / srat_y;

            CSize size ( bm.bmWidth, bm.bmHeight );
            
            memDC.DPtoLP ( &size );

                  
            pDC->SetMapMode(MM_TEXT);

            if(fmsgraph->m_FitToBorder)
                  pDC->StretchBlt(sz.cx, sz.cy, szr.cx, szr.cy, &memDC, 0, 0, size.cx, size.cy, SRCCOPY);
            else
                  pDC->StretchBlt(sz.cx, sz.cy, size2.cx, size2.cy, &memDC, 0, 0, size.cx, size.cy, SRCCOPY);
            pDC->SetMapMode(MM_TWIPS);
      }

...
0
 
LVL 7

Accepted Solution

by:
galkin earned 100 total points
ID: 1313979
Check if your printer supports StretchBlt with GetDeviceCaps with RASTERCAPS and RC_STRETCHBLT.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jurasz
ID: 1313980
I've tried it already, but it's OK ((pDC->GetDeviceCaps(RASTERCAPS) & RC_STRETCHBLT) != 0)
It seems weird to me because in PrintPreview it works fine.
0
 
LVL 7

Expert Comment

by:galkin
ID: 1313981
I think your problem is that you create memory DC compatible with printer DC. Prenter DC if you are using b/w printer has only two colors so error probably occurs when you try to select bitmap into memory DC. You should create 24 bit DIB. In this case no palette is needed and printer performs the best dithering. To set DIB bits to printer DC use StretchDIBits function.
0
 

Author Comment

by:jurasz
ID: 1313982
Thanks, Galkin. It was that.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
repeatEnd java challenge 42 85
fizzArray2 challenge 1 102
unix example issues 18 106
how to use laptop or pad camera in vb.net windows application 2 105
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question