WXWIDGETS应用于WXStaticBitMap时,屏幕截图将大部分图像留为空白



当我尝试捕获wxwidgets屏幕截图时,它没有显示出任何错误。如果我保存它,它可以完美保存。但是,当我尝试将其添加到静态位图中时,它只是显示了一些图标,所有内容都会透明。

wxClientDC dcScreen(GetParent());
//Get the size of the screen/DC
wxCoord screenWidth, screenHeight;
dcScreen.GetSize(&screenWidth, &screenHeight);
//Create a Bitmap that will later on hold the screenshot image
//Note that the Bitmap must have a size big enough to hold the screenshot
//-1 means using the current default colour depth
screenshot.Create(screenWidth, screenHeight,-1);
//Create a memory DC that will be used for actually taking the screenshot
wxMemoryDC memDC;
//Tell the memory DC to use our Bitmap
//all drawing action on the memory DC will go to the Bitmap now
memDC.SelectObject(screenshot);
//Blit (in this case copy) the actual screen on the memory DC
//and thus the Bitmap
memDC.Blit( 0, //Copy to this X coordinate
         0, //Copy to this Y coordinate
         screenWidth, //Copy this width
        screenHeight, //Copy this height
        &dcScreen, //From where do we copy?
        0, //What's the X offset in the original DC?
        0  //What's the Y offset in the original DC?
     );
//Select the Bitmap out of the memory DC by selecting a new
//uninitialized Bitmap
memDC.SelectObject(wxNullBitmap);
staticbitmap1->SetBitmap(screenshot);

在wxstaticbitmap文档中,您可以阅读:

某些平台上的本机实现仅用于显示 对话框中的小图标。

如果要便便显示较大的图像,则可以使用通用 在 。

看来您的屏幕截图是不是小,因此OS弄乱了您。因此,请遵循建议并使用wxGenericStaticBitmap

最新更新