Search code examples
macoscocoacore-graphicscore-animation

How to make CGWindowListCreateImage render correct background color?


Capturing an image of an off-screen window with CGWindowListCreateImage is a common way to create QuickLook style zoom-in animations, but this seems create an image with the wrong background colour, slightly lighter than the real window.

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?

EDIT: I created a demonstration app for this problem. It is a bit large and complex for a Stack Overflow question, but the relevant code is probably in the ZoomingWindow.m methods takeSnapshot and makeAndPrepareSnapshotWindow.

Comparison of the final window and snapshot


Solution

  • Setting the window appearance to textured in Interface Builder fixed this. Of course that also changes the color of the window, but that is acceptable in this particular case.