According to lpBits
of CreateBitmap, you may need to initialize the color data. And you should try CreateCompatibleBitmap.
How to remove thin black border while printing bitmap in Win32 app
Shyam Butani
20
Reputation points
Hello,
I'm working on C++/WinRT application, and trying to print bitmap using printer. But I'm getting thin black border on the printed page. I'm doing similar to below code snippet.
// Printer HDC
HDC hdc_printer = CreateDCW (NULL, L"My Printer Name", NULL, NULL);
// Getting height and width from the printer
int width = GetDeviceCaps (hdc_printer, HORZRES);
int height = GetDeviceCaps (hdc_printer, VERTRES);
// Creating bitmap
HBITMAP bitmap = CreateBitmap (width, height, 1, 32, NULL);
// Draw bitmap
// SelectObject (hdc_bitmap, bitmap)
// StartDoc (...)
// StartPage (...)
// Print bitmap using printer
BitBlt (hdc_printer, 0, 0, width, height, hdc_bitmap, 0, 0, SRCCOPY);
// EndPage (...)
// EndDoc (...)
Please help me to understand the reason behind this and how to remove this border.
Thanks.
1 answer
Sort by: Most helpful
-
Xiaopo Yang - MSFT 11,496 Reputation points Microsoft Vendor
2024-04-10T02:03:21.4366667+00:00