Dan*_*iel 8 screen objective-c capture
有谁知道如何在mac os中使用目标c捕获屏幕?更具体地说,我如何捕获活动/聚焦应用程序屏幕,然后将图像创建到指定路径.
任何帮助都非常感谢.
@Daniel,你不需要理解和实现整个"掠夺之子".你只需要下面的代码.
以下功能将为您提供屏幕截图
// 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);
Run Code Online (Sandbox Code Playgroud)
使用以下代码将其转换为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;
Run Code Online (Sandbox Code Playgroud)