Search code examples
c#directxbuffersharpdxdxgi

Capturing Mouse Cursor and Draw on Image Buffer c#


I'm working on a screen recording application and I can capture the screen but without mouse cursor. I used DXGI, SharpDX and Media Foundation.

My question is. Is it possible to write the mouse cursor on image buffer so the the image buffer I sent to mediafoundation has already mouse cursor in it before it encode to a video? Saw lot of sample here how to include mouse cursor in screen capture but what they did is convert both image to bitmap and then combine both. I already tried that but performance is not good and cpu usage is so high and also fps is low. without cursor I can capture 60fps smooth. Thanks in Advance


Solution

  • it is possible implement your task, but it needs copy some code from C++ on C#. In my project Desktop Screen Capture on Windows via Windows Desktop Duplication API with Drawing of Cursor's Image you can find the suitable solution. It is based on using a special Direct3D11 texture - it is created with MiscFlag - D3D11_RESOURCE_MISC_GDI_COMPATIBLE. It allows GDI rendering on the surface via IDXGISurface1::GetDC and using of Windows function DrawIconEx for drawing cursor's image. The drawing of cursor is executed by Windows function and is done in context of video memory.

    Regards.