1

是否可以捕获 NSCursor 窗口的图像?这是我的代码

获取光标窗口的原始值

let level = CGWindowLevelForKey(.CursorWindowLevelKey).int

我有一个方法可以使用 CGWindowListCopyWindowInfo 遍历屏幕上的所有窗口并返回“窗口服务器”拥有的光标窗口的窗口编号

let number = self.windowNumber(level, screen: screen, options: nil) //returns proper window number
let frame = screen.frame //screen is the current NSScreen that the mouse is in. 

let cgimage = CGWindowListCreateImage(frame, .OptionIncludingWindow, CGWindowID(number), .Default)!

转换为 NSBitmapImageRep

let cursor = NSBitmapImageRep(CGImage: cgimage)

然后将光标的屏幕截图保存到磁盘。

这适用于所有其他窗口,除了保存空白窗口的光标。我也尝试过使用一堆不同类型的框架,但没有成功。我认为这是因为 CGWindowListCreateImage 自动省略了光标窗口。是否有可能阻止它忽略它?也许复制窗口并捕获它?

我尝试过的其他事情

  1. 使用获取图像NSCursor.currentCursor().image但因为我的应用程序是仅后台应用程序,我被迫使用NSCursor.currentSystemCursor().image它总是返回非视网膜图像。
  2. 弄清楚哪个NSCursor.currentSystemCursor().image正在返回并尝试获取视网膜版本......只是无法比较真正带回哪个实例。
4

0 回答 0