Search code examples
swiftmacosunity-game-engineobjective-c++unity3d-native-plugins

Is there a way to take a screen shot in macOS programmatically?


It seems like all the old frameworks have been deprecated (e.g. CGWindowListCreateImage) in favor of ScreenCaptureKit. Unfortunately it only offers streaming. Is there a simpler way I can get a screenshot of the user's display?

Given displayId, x, y, width and height, I need a function to return the byte data of the desktop screen capture image. It's for a Unity3d native plugin.

I've tried ScreenCapture kit but it's just not right for this use case.

Everything else is deprecated.


Solution

  • Yes, it is, in WWDC 23, ScreenCaptureKit API were introduced to capture screenshots programmatically.

    Please refer here :

    What’s new in ScreenCaptureKit

    https://developer.apple.com/videos/play/wwdc2023/10136/?time=586