开发者

screen capture using objective c for mac

Does anyone has any idea how can I capture screen using objective c in mac os? to be more specific, how can I capture the active / focused application screen then create an image into a specified path.

Any help is highly 开发者_JAVA技巧appreciated.


@Daniel, You don't need to understand and implement the whole "Son of Grab". You just need the code below.

The following function will give you the screenshot

// 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);

Use the following code to convert it to a 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;


Have you checked out Apple's “Son of Grab” for capturing images of windows with the CGWindow api?


You can also check Apple's OpenGLScreenSnapshot

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜