Page 1 of 1

save screen as bitmap file mac11

Posted: Tue Sep 15, 2020 11:42 am
by Anil8753
I was using the following code to capture the screenshot of a wxWindow (on both Windows and MacOS).

Code: Select all

void CaptureScreenShot(wxWindow* pWin)
{
    wxClientDC bgdc(pWin);

    int width = bgdc.GetSize().GetWidth();
    int height = bgdc.GetSize().GetHeight();

    //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
    wxBitmap bmpWin = wxBitmap(width, height, -1);

    wxMemoryDC memDC;
    memDC.SelectObject(bmpWin);
    memDC.Blit(0, 0, width, height, &bgdc, 0, 0);

    wxASSERT(bmpWin.IsOk());
    bmpWin.SaveFile("path to filesytem", wxBitmapType::wxBITMAP_TYPE_BMP);
}
On Mac11 (Bigsur) captured bitmap is black
Can someone pointout what is wrong with shared code snippet that causing Black bitmap on Mac11 Bigsur.
Till Mac 10.15 this code was working.

Re: save screen as bitmap file mac11

Posted: Tue Sep 15, 2020 5:02 pm
by ONEEYEMAN
Hi,
I presume you don't see an assert?

Thank you.

Re: save screen as bitmap file mac11

Posted: Wed Sep 16, 2020 6:25 am
by Anil8753
yes, I do not see wxAssert. Saved bmp is black.

Re: save screen as bitmap file mac11

Posted: Wed Sep 16, 2020 7:05 am
by ONEEYEMAN
Hi,
How did you build the library? What is your configure line?

Thank you.

Re: save screen as bitmap file mac11

Posted: Wed Sep 16, 2020 8:19 am
by doublemax
I don't think there is anything wrong in your code or your library. It's probably caused by a change in OS X. It might even be a privacy protection matter.

Try asking again on the wx-dev mailing list where the main author of the OSX port, Stefan Csomor might be able to answer.

Re: save screen as bitmap file mac11

Posted: Thu Sep 17, 2020 4:58 pm
by Anil8753
Thank you, Stefan helped me resolved this issue. wx3.1.4 (primarily focused on mac11 issues) has the fix.
I need to copy the wxBitmap wxWindowDCImpl::DoGetAsBitmap(const wxRect *subrect) const from src/osx/cocoa/utils.mm from 3.1.4 to my version

https://groups.google.com/g/wx-dev/c/KD ... PvhcIGBAAJ