existe-t-il un moyen de prendre une capture d'écran (ou d'avoir accès à une image) de l'écran actuel de l'écran sur un Mac? p>
de préférence, en C ++, pas objectif-c. p>
3 Réponses :
Utiliser la scrupule ScreenCapture (1). p>
Invoquer-le avec système () ou POSIX_SPOWN (). P>
Je recommande l'utilisation des services d'affichage de quartz forts> et de la fonction cgdisplaycreateImage () code> p>
J'ai travaillé sur le même problème. C'est le code que j'ai proposé après avoir cherché un moment.
CGImageRef screenShot = CGWindowListCreateImage( CGRectInfinite, kCGWindowListOptionOnScreenOnly, kCGNullWindowID, kCGWindowImageDefault); //std::string image_name = "/Users/nikhil/Desktop/SC_"; //image_name+=str; //cout<<str<<endl; //image_name+=".jpg"; //cout<<image_name<<endl; CFStringRef file = CFSTR("/Users/nikhil/Desktop/SC.jpg"); CFStringRef type = CFSTR("public.jpeg"); CFURLRef urlRef = CFURLCreateWithFileSystemPath( kCFAllocatorDefault, file, kCFURLPOSIXPathStyle, false ); CGImageDestinationRef image_destination = CGImageDestinationCreateWithURL( urlRef, type, 1, NULL ); CGImageDestinationAddImage( image_destination, screenShot, NULL ); CGImageDestinationFinalize( image_destination );