Screenshot captured using BitBlt in c# resulted a black image on Windows 10. Please help me to resolve this.
Screenshot is black image for
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.