Screenshot captured using BitBlt in C# results a black image on Windows 10

前端 未结 1 744
情深已故
情深已故 2021-01-03 08:21

Screenshot captured using BitBlt in c# resulted a black image on Windows 10. Please help me to resolve this.

Screenshot is black image for

相关标签:
1条回答
  • 2021-01-03 08:59

    Hardware accelerated windows are rendered using overlay mode, which means that your BitBlt only gets pixels that say "Hey, this is overlay!". When the overlay isn't being rendered, this results in a black image - and if it is being rendered, you always see the current render, not something frozen in time. You're not capturing the pixels being shown on the screen, just some internal details of how window rendering works.

    The solution is fortunately quite simple:

    BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, 
           CopyPixelOperation.SourceCopy | CopyPixelOperation.CaptureBlt);
    

    (you can modify your BitBlt P/Invoke definition to use CopyPixelOperation instead of int, or just cast those values to int yourself).

    As a side-note, please don't forget to check the return values and handle errors accordingly.

    0 讨论(0)
提交回复
热议问题