Capturing a window with WPF

后端 未结 2 1946
萌比男神i
萌比男神i 2021-02-10 19:02

With Windows Presentation Foundation, if I have an HWND, how can I capture it\'s window as an image that I can manipulate and display?

2条回答
  •  闹比i
    闹比i (楼主)
    2021-02-10 19:16

    You can:

    1. CreateBitmap() to create a hBitmap
    2. Call GetDC() on the hWnd
    3. BitBlt() the contents to the hBitmap
    4. ReleaseDC()
    5. Call Imaging.CreateBitmapSourceFromHBitmap() to create a managed BitmapSource
    6. DeleteObject() on the hBitmap
    7. Use the BitmapSource as desired

    Steps 1-4 and 6 use the Win32 API (GDI to be precise), Steps 5 and 7 are done using WPF

提交回复
热议问题