2010-09-26 72 views
1

我想用C/C++在OSX上截屏。 到目前为止,这是我得到:使用C++和CGWindow API的OSX屏幕截图

#import <ApplicationServices/ApplicationServices.h> 

int main(int argc, char** argv) { 
    CGImageRef screenShot = CGWindowListCreateImage(CGRectInfinite, 
     kCGWindowListOptionOnScreenOnly, kCGNullWindowID, kCGWindowImageDefault); 

    CFStringRef file = CFSTR("/Users/aduh/Desktop/lala.jpg"); 
    CFStringRef type = CFSTR("public.jpeg"); 
    CFURLRef urlRef = CFURLCreateWithString(NULL, file, NULL); 
    CGImageDestinationRef idst = CGImageDestinationCreateWithURL(urlRef, type, 1, NULL); 
    CGImageDestinationAddImage(idst, screenShot, NULL); 
    CGImageDestinationFinalize(idst);} 

它编译罚款,但没有真正发生。我可能只是犯了一个愚蠢的错误,所以如果任何人都可以指出我的方向是正确的,那就太好了!

回答

0

更换CFURLCreateWithString()CFURLCreateWithSystemPath()

1

如上所述的家伙,这可以是固定的这个样子,我还使用C++,如果它的事项:

CFURLRef urlRef = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, file, kCFURLPOSIXPathStyle, false);