-1

hi guys im making my own flutter desktop program but when trying to make a fucntion that capturing the window where flutter widget's area is located i have troubled..

  • first, i tried to transparent the program's background and capture the widget(by using flutter_acrylic and RenderRepaintBoundary).transparent image
  • when i caputred widget the image wasnt include transparent window.. but only tranparent color was. because caputre algorithm see only the widget. im blocked in this problem.widget capture image

anyone who have idea for this problem please give me wisdom... +Now I tying to get information about the win32 API. Any ideas on win32 capture API would be much appreciated.

output image

breakeme
  • 1
  • 1

1 Answers1

0

About win32 capture API, you can use GDI BitBlt function. Here is a MSDN sample Capturing an Image.

You need to find the flutter desktop program window's handle with FindWindow, then get the rect range, and capture the window from DC.

HDC hWndDC = GetWindowDC(hwnd);
RECT capture_rect{ 0,0,0,0 }; 
RECT wnd_rect; 
RECT real_rect; 

GetWindowRect(hwnd, &wnd_rect);
DwmGetWindowAttribute(hwnd, DWMWINDOWATTRIBUTE::DWMWA_EXTENDED_FRAME_BOUNDS, &real_rect, sizeof(RECT));

int offset_left = real_rect.left - wnd_rect.left;
int offset_top = real_rect.top - wnd_rect.top;
capture_rect = RECT{ offset_left,offset_top,real_rect.right - real_rect.left + offset_left,real_rect.bottom - real_rect.top + offset_top };    

//capture_rect ?? wnd_rect (You can calculate the capture_rect based on the size of your window)

int width = capture_rect.right - capture_rect.left;
int height = capture_rect.bottom - capture_rect.top;  

HDC hMemDC = CreateCompatibleDC(hWndDC);
HBITMAP hBitmap = CreateCompatibleBitmap(hWndDC, width, height);
SelectObject(hMemDC, hBitmap);

BitmapPtr bitmap;

bool ok = BitBlt(hMemDC, 0, 0, width, height, hWndDC, capture_rect.left, capture_rect.top, SRCCOPY);

DeleteDC(hWndDC);
DeleteDC(hMemDC);
DeleteObject(hBitmap);
Junjie Zhu - MSFT
  • 2,086
  • 1
  • 2
  • 6