Solved

Print bitmap in OnPrint()

Posted on 1998-01-13
6
381 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 

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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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
Windows Drag & Drop Location 2 108
VBA "SendKeys" Syntax for Multiple Keystrokes 7 117
fizzArray  challenge 1 96
Not needed 13 119
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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…

856 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