?
Solved

Print bitmap in OnPrint()

Posted on 1998-01-13
6
Medium Priority
?
388 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 400 total points
ID: 1313979
Check if your printer supports StretchBlt with GetDeviceCaps with RASTERCAPS and RC_STRETCHBLT.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

719 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