【发布时间】:2010-12-13 17:44:23
【问题描述】:
有谁知道如何在 mac os 中使用目标 c 捕获屏幕?
更具体地说,如何捕获活动/聚焦的应用程序屏幕,然后将图像创建到指定路径中。
非常感谢任何帮助。
【问题讨论】:
标签: objective-c screen capture
有谁知道如何在 mac os 中使用目标 c 捕获屏幕?
更具体地说,如何捕获活动/聚焦的应用程序屏幕,然后将图像创建到指定路径中。
非常感谢任何帮助。
【问题讨论】:
标签: objective-c screen capture
您是否查看过 Apple 的 “Son of Grab” 以使用 CGWindow api 捕获窗口图像?
【讨论】:
@丹尼尔, 你不需要理解和实现整个“Son of Grab”。你只需要下面的代码。
下面的函数会给你截图
// This just invokes the API as you would if you wanted to grab a screen shot. The equivalent using the UI would be to
// enable all windows, turn off "Fit Image Tightly", and then select all windows in the list.
CGImageRef screenShot = CGWindowListCreateImage(CGRectInfinite, kCGWindowListOptionOnScreenOnly, kCGNullWindowID, kCGWindowImageDefault);
使用以下代码将其转换为 NSImage
NSBitmapImageRep *bitmapRep = [[NSBitmapImageRep alloc] initWithCGImage:screenShot];
// Create an NSImage and add the bitmap rep to it...
NSImage *image = [[NSImage alloc] init];
[image addRepresentation:bitmapRep];
[bitmapRep release];
bitmapRep = nil;
【讨论】:
CFRelease(screenShot);,以免泄露。
你也可以查看苹果的 OpenGLScreenSnapshot
【讨论】: