2009-11-06 1 views
7

Quelqu'un at-il une idée de comment puis-je capturer l'écran en utilisant l'objectif c dans mac OS? pour être plus précis, comment puis-je capturer l'écran de l'application active/ciblée puis créer une image dans un chemin spécifié.
Toute aide est fortement appréciée.capture d'écran en utilisant l'objectif c pour mac

Répondre

4

Avez-vous vérifié le “Son of Grab” d'Apple pour capturer des images de fenêtres avec l'API CGWindow?

+1

ouais, je l'ai vu, je suis plutôt nouveau pour objectif c , Fils de Grab est un peu difficile pour moi. mon exigence est très simple, créer une application qui fonctionne en arrière-plan, en répondant à certains critères, il suffit de capturer la fenêtre focalisée actuelle et de créer une image sur un chemin spécifié – Daniel

1

Vous pouvez également consulter OpenGLScreenSnapshot d'Apple

7

@ Daniel, Vous n'avez pas besoin de comprendre et de mettre en œuvre l'ensemble « Fils de Grab ». Vous avez juste besoin du code ci-dessous.

La fonction suivante vous donnera la capture d'écran

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

Utilisez le code suivant pour le convertir en un 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;