Elmi
Elmi

Reputation: 6213

Capture wxFrame contents and save to file

I'm using following core to capture the contents of my MainWin which is a wxFrame:

void MainWin::capture(wxString path)
{   
   wxClientDC dcWindow(this);
   wxCoord screenWidth, screenHeight;

   dcWindow.GetSize(&screenWidth, &screenHeight);

   wxBitmap screenshot(screenWidth, screenHeight, -1);
   wxMemoryDC memDC;
   memDC.SelectObject(screenshot);
   memDC.Clear();
   memDC.Blit(0,0, //Copy to coordinate
              screenWidth,screenHeight,
              &dcWindow,
              0,0 //offset in the original DC
              );
   memDC.SelectObject(wxNullBitmap);
   screenshot.SaveFile(path, wxBITMAP_TYPE_PNG);
}

In principle it works but it saves only parts of my whole screen (e.g. from the toolbar only first three images are saved, all other ones are missing), the missing parts are just black.

What am I doing wrong here? Do I have to refresh something prior to blitting? Or what else could be the reason?

Thanks!

Upvotes: 0

Views: 114

Answers (1)

Xaviou
Xaviou

Reputation: 309

I've tried your code, and I also ran into strange result : a simple frame with a panel, a button and a textbox on it, and the result is that all backgrounds (panel, textbox) are transparents, and the text of the button does the same thing.

It seems that the png handler is responsible of this : I've tried saving to a jpeg file and all went ok.

You should try using jpeg to see if you have the same problem with your toolbar images or not.

Regards Xav'

Upvotes: 1

Related Questions