Capture screen using c lens for mac

Does anyone know how I can capture a screen using object c in mac os? to be more specific, how can I capture the screen of an active / focused application and then create an image in the specified path.
Any help is appreciated.

+7
objective-c screen capture
source share
3 answers

@Daniel, you don’t need to understand and realize the whole “Son of robbery”. You just need the code below.

The following function will give you a 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 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; 
+7
source share

Have you tested Apple's "Robbery Son" to capture window images using the CGWindow api?

+4
source share

You can also check Apple OpenGLScreenSnapshot

+1
source share

All Articles