Solved

Print bitmap in OnPrint()

Posted on 1998-01-13
6
379 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
conditional code and condition difference 9 83
lucky13 challenge 11 146
canBalance challenge 34 86
Excel file not created as expected 7 72
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

803 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