When using GDI to capture the window image and save it as BMP, the shadow around the window becomes black. Is there any way to solve it?

勇强 韩 136 Reputation points
2021-09-02T05:29:06.933+00:00

RT, Or is there a way to get the width of the shadow, the width of the red box in the attachment screenshot?
beforce capture:
128573-window-shandow1.jpg

after capture:
128574-window-shandow-gdi-capture.png

capture desktop image:  
CreateCompatibleDC  
CreateCompatibleBitmap  
SelectObject  
  
capture window image:  
CreateCompatibleDC  
CreateCompatibleBitmap  
SelectObject  
  
compose window to desktop image:  
StretchBlt  
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,481 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 113.9K Reputation points
    2021-09-02T05:51:11.013+00:00

    Try specifying ‘SRCCOPY | CAPTUREBLT’ in your BitBlt or StretchBlt calls.

    If it does not help, then try calling DwmGetWindowAttribute(…, DWMWA_EXTENDED_FRAME_BOUNDS, …). It should return the rectangle without the black borders. Also use PhysicalToLogicalPointForPerMonitorDPI to convert the coordinates.

    Check an example in C# that can be done in C++: https://learn.microsoft.com/en-us/answers/questions/522265/.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful