可可:拍摄桌面墙纸的屏幕快照(没有图标和窗口) [英] Cocoa: take screenshot of desktop wallpaper (without icons and windows)

查看:65
本文介绍了可可:拍摄桌面墙纸的屏幕快照(没有图标和窗口)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以捕获没有桌面项目和任何可能打开的窗口(即仅墙纸)的Mac OS X桌面?

Is is possible to capture the Mac OS X desktop without desktop items and any windows that may be open (i.e. just the wallpaper)?

我已经尝试过 CGWindowListCreateImage CGWindowListCreateImageFromArray CGDisplayCreateImage ,但是没有运气。

I've experimented with CGWindowListCreateImage, CGWindowListCreateImageFromArray, and CGDisplayCreateImage, but no luck.

基本上,我试图不使用 [NSWorkspace desktopImageURLForScreen:] 捕获桌面墙纸(这是一个沙盒应用程序

Essentially I'm trying to capture the desktop wallpaper without using [NSWorkspace desktopImageURLForScreen:] (it's a sandboxed app without access to the file system).

推荐答案

您需要小心测试这是否仍然正确,但是桌面窗口位于Finder(由Dock绘制)下方。将 kCGWindowListOptionOnScreenBelowWindow CGWindowListOption 传递给 CGWindowListCreateImage 应该会为您提供

You'll need to be careful to test that this is still correct, but the desktop window sits below the Finder (it's drawn by the Dock). Passing the kCGWindowListOptionOnScreenBelowWindow CGWindowListOption to CGWindowListCreateImage should get you what you want (unless something else is drawing below that level).

否则,您需要使用 CGWindowListCreate 和遍历响应,不包括停靠窗口在窗口级别 kCGMinimumWindowLevel + 19 中未绘制的任何内容。

Otherwise, you'll need to use CGWindowListCreate and iterate through the response excluding anything that isn't drawn by the dock at the window level kCGMinimumWindowLevel + 19.

当有多个屏幕时,它会变得有些棘手,但希望此信息足以让您执行所需的操作。

It gets kind of tricky when there are multiple screens, but hopefully this information is enough for you to do what you need.

这篇关于可可:拍摄桌面墙纸的屏幕快照(没有图标和窗口)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆