Solved

Print bitmap in OnPrint()

Posted on 1998-01-13
6
372 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ORA-01403: no data found 43 82
NotAlone Challenge 20 70
Use of condition with 'serial' in ansible 2 36
changeXy challenge 13 57
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: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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 remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now