save screen as bitmap file mac11 Big sur

44 views
Skip to first unread message

anilku...@gmail.com

unread,
Sep 16, 2020, 2:57:24 PM9/16/20
to wx-dev
I was using the following code to capture the screenshot of a wxWindow (on both Windows and MacOS).

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 point out what is wrong with shared code snippet that causing Black bitmap on Mac11 Bigsur.
Till Mac 10.15 this code was working.


Stefan Csomor

unread,
Sep 17, 2020, 3:42:27 AM9/17/20
to wx-...@googlegroups.com
Hi

> On Mac11 (Bigsur) captured bitmap is black
> Can someone point out what is wrong with shared code snippet that causing Black bitmap on Mac11 Bigsur.
> Till Mac 10.15 this code was working.

For 11.0 please use the current master or at least 3.1.4

Best,

Stefan

anilku...@gmail.com

unread,
Sep 17, 2020, 7:18:18 AM9/17/20
to wx-dev
Hi Stefan, Surely I will do it but upgrading wx3.0 to wx3.1.4 is not feasible at this time. 
If you can please point out the workaround/reason of black bitmap, will be great help.

Vadim Zeitlin

unread,
Sep 17, 2020, 7:22:27 AM9/17/20
to wx-...@googlegroups.com
On Thu, 17 Sep 2020 04:18:18 -0700 (PDT) anilku...@gmail.com wrote:

a> Hi Stefan, Surely I will do it but upgrading wx3.0 to wx3.1.4 is not
a> feasible at this time.

Just curious, why is it the case for you? Normally the API is 99%
compatible, so it should be as easy as recompiling with the new version.

a> If you can please point out the workaround/reason of black bitmap, will be
a> great help.

There are just too many changes related to macOS 11 in 3.1, I don't think
it's going to be realistically possible to backport them to 3.0.

Regards,
VZ

anilku...@gmail.com

unread,
Sep 17, 2020, 7:53:07 AM9/17/20
to wx-dev
I would love to upgrade to the latest. Unfortunately, my organization has stppoed me to upgrade, they have planned organization wise wx upgrade in next year March. The only option I have to patch the wx3.0. This is possible only if I know the reason. :)

Stefan Csomor

unread,
Sep 17, 2020, 8:15:38 AM9/17/20
to wx-...@googlegroups.com
Hi

> I would love to upgrade to the latest. Unfortunately, my organization has stppoed me to upgrade, they have planned organization wise wx upgrade in next year March. The only option I have to patch the wx3.0. This is possible only if I know the reason. :)

I don't have the time to test thing thoroughly, you could try copying

wxBitmap wxWindowDCImpl::DoGetAsBitmap(const wxRect *subrect) const

from src/osx/cocoa/utils.mm from 3.1.4 to your version

Best,

Stefan

anilku...@gmail.com

unread,
Sep 17, 2020, 9:11:53 AM9/17/20
to wx-dev
Thank you Stefan, copying wxWindowDCImpl::DoGetAsBitmap from master to wx3.0 worked!
Reply all
Reply to author
Forward
0 new messages