microsoft / WindowsCompositionSamples

The Windows Composition Samples have moved here: https://github.com/microsoft/WindowsAppSDK-Samples/tree/main/Samples/SceneGraph
https://github.com/microsoft/WindowsAppSDK-Samples/tree/main/Samples/SceneGraph
MIT License
1.12k stars 287 forks source link

Taking a screenshot of windows with AllowsTransparency="True" #358

Closed Kybs0 closed 2 years ago

Kybs0 commented 2 years ago

Hi, I'm trying to capture window by using Win32.PrintWindow。 My purspose is capture any kind of window with the window handle,then use the captured image to do more operations.

But I found captured image is black when capturing window has set AllowsTransparency="True".I have captured all window that valid and visible in my screens,some windows displays black: image

I found other devlopers also met this question:

A fixed issue is similar to my problem above: https://github.com/microsoft/Windows.UI.Composition-Win32-Samples/issues/41. Help confirm if it's the same issue,and hope any reply. Thanks!

Here is my environment

kevinguo305 commented 2 years ago

Thanks for the comment!

PrintWindow is not designed to work with AllowsTransparency being set to true. The best option here is to switch to Windows.Graphics.Capture API. Keep in mind that the API only works on RS5 and above. Here's a GitHub sample repository which I think should help with how to use the API.

I'm going to close this issue, but feel free to reopen if you feel that your issue has not been addressed!