question

HenryShawn-0817 avatar image
2 Votes"
HenryShawn-0817 asked MladenKrmarevi-8711 answered

Anyone else unable to print bitmaps on docs sent to a printer?

Is anyone else having trouble getting bitmaps to print on documents sent to a printer? I was working on some code yesterday, and it was working just fine. This morning however, it simply stopped working, without making any code changes (was continuing my validation testing). I went back to some older projects that use the same method for printing and now they aren't working either. I have about 5 or 6 applications which perform a similar print operation, and every one I've tested seems to no longer be working. I'm beginning to think something changed in the OS, as these applications which have been working reliably for years just stopped working today. Using CDC for printing, with a bitmap included as a resource in my project. Here's the code: CBitmap BmpCusomterLogo; CDC MemDC; // Load the bitmap from the resource BmpCusomterLogo.LoadBitmap( IDB_BITMAP1 ); // Create a memory device compatible with the above CPaintDC variable MemDC.CreateCompatibleDC( pDC ); // Select the new bitmap CBitmap *BmpPrevious = MemDC.SelectObject( &BmpCusomterLogo ); // Copy the bits from the memory DC into the current dc pDC->BitBlt(1480, 400, 1800, 364, &MemDC, 0, 0, SRCCOPY ); // Restore the old bitmap pDC->SelectObject( BmpPrevious );

vs-general
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I forgot to mention that if I change the raster option from SRCCOPY to BLACKNESS, I can see a black box printed where the bitmap should be

0 Votes 0 ·

Did you check if printing works using other programs, such as Paint or Word?

0 Votes 0 ·

My old codes with StretchDIBits to the Printer DC work fine for me (Windows 10 1909, 18363.1379)

0 Votes 0 ·
DylanZhu-MSFT avatar image
0 Votes"
DylanZhu-MSFT answered

Hi HenryShawn,

You can try to delete the .obj and .vs folders, then try to re-build your project.

Best Regards,
Dylan


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

IgorDelovski-1450 avatar image
1 Vote"
IgorDelovski-1450 answered IgorDelovski-1450 commented

Seems like a Windows update ruined your code. SelectObject() fails here. Uninstall KB5000808 or KB5000802. Since most applications print their images just fine, I wonder how on earth everybody sends images to the printer?

· 7
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Uninstalling KB5000808 worked for me.
Not sure if the issue is with SelectObject() or the handle returned by LoadImageA().

0 Votes 0 ·

I tried doing the same functions with the main window HDC on WM_PAINT like with the printer DC and the image shows up like expected so the problem is with the printer device context, not the SelectObject and LoadImage functions.

0 Votes 0 ·

Confirmed. When I create a compatible DC off the main window, it will select in. Doing so off of the printer DC fails.

0 Votes 0 ·
Show more comments

I am pretty confident it is LoadImage() since the HBITMAP returned by our PNG loader selects into the device context fine. I also tried 32bit/64bit and the widechar version of LoadImage(). Broken.

Calling GetObject() on the handle returned from LoadImage() appears to return valid data.

0 Votes 0 ·
MladenKrmarevi-8711 avatar image
0 Votes"
MladenKrmarevi-8711 answered MladenKrmarevi-8711 edited

I have the same problem, thought something was wrong with the printer drivers after the update but then I tried printing to pdf and the same problem was happening.
I also tried running the same exe on a machine that wasn't updated and there it worked fine, the winspool.dll might be messed up or there is an OS level problem.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

EschBartvan-2553 avatar image
0 Votes"
EschBartvan-2553 answered EschBartvan-2553 published
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MladenKrmarevi-8711 avatar image
0 Votes"
MladenKrmarevi-8711 answered

It seems to be working now for me, I'm not sure which windows update fixed it works fine now.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MladenKrmarevi-8711 avatar image
0 Votes"
MladenKrmarevi-8711 answered

It seems to be working now for me, I'm not sure which windows update fixed it but it works fine now.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.