CGWindowListCreateImage renders wrong background for off-screen image

Capturing an image of an off-screen window with CGWindowListCreateImage is a common way to create QuickLook-style zoom-in animations, but seems to give the wrong background colour, slightly whiter than the actual window has when it is shown onscreen.

This causes a flash at the end of the animation which kind of ruins the effect.

Does anyone have any idea why this happens and what can be done about it?

If I set the window appearance to textured in Interface Builder this problem goes away, but then I have the problem that the window looks different (darker) than other windows in the app. I can set the window background to a custom color that makes it match the others windows, but then it still looks off in older macOS versions.

I made a sample project that illustrates the problem here: https://github.com/angstsmurf/WindowCaptureTest.

CGWindowListCreateImage renders wrong background for off-screen image
 
 
Q