如何以编程方式捕获mac osx的辅助监视器

时间:2014-07-26 05:33:56

标签: objective-c macos cocoa monitor screen-capture

#define MAX_DISPLAYS 32
CGDirectDisplayID activeDisplays[MAX_DISPLAYS];
CGDisplayCount displayCount;

//code for getting screen IDS 

void screenIDs()
{ 
    CGDisplayErr err; 

    // get the active displays

    err = CGGetActiveDisplayList(MAX_DISPLAYS, activeDisplays, &displayCount);
    if ( err != kCGErrorSuccess ) {
        printf("Error: cannot get displays:\n%d\n", err);
        return;
    }

    int i;
    for (i=0; i<displayCount; i++) {
        printf("%i\n", activeDisplays[i]);
        CGRect rect= CGDisplayBounds(activeDisplays[i]);
        NSLog(@"%f %f %f %f",rect.origin.x,rect.origin.y,rect.size.width,rect.size.height);
    }
}



//Screen capture for Lion OSX

NSData* currentScreenPixelData;
char* capture_screenShot() {
    char* screenData;

    if(_isOSHigherThanSnowLeopard)
    { 
        CGImageRef screenShot = CGDisplayCreateImage(activeDisplays[0]);

        if(screenShot != nil)    
        {
            CGDataProviderRef dataRef = CGImageGetDataProvider(screenShot);

            if(currentScreenPixelData)
            {
                [currentScreenPixelData release];
            }

            currentScreenPixelData = (NSData*) CGDataProviderCopyData(dataRef);
            screenData = (char*)[currentScreenPixelData bytes];

            CGImageRelease(screenShot);
        }
    }

    return screenData;
}

我已将activeDisplays [0](主监视器)变量更改为activeDisplays [1](辅助监视器)仍在显示 &#34; CGImageRef screenShot = CGDisplayCreateImage(activeDisplays [0]);&#34;但它仍然是捕捉主要显示

0 个答案:

没有答案