Search code examples
c++screenshotwxwidgets

Save wxWidgets window screenshot


I have a wxWidgets application. I wan't to get the window screen as image and save it into a file.

I know that the wxImage can be saved easily:

wxImage im;
im.Create(window_width, window_height)
/**assign some data**/
im.SaveFile("path/screen.png", wxBITMAP_TYPE_PNG);

However, how do I gather the window (and I want only the window!) pixel data?


Solution

  • You can use wxClientDC to access the window data. Then just Blit() them to a wxMemoryDC with a wxBitmap selected into it and finally convert the bitmap to wxImage.