В моем приложении какао я хочу сделать скриншот обоев рабочего стола для нескольких экранов. Я нашел эту ссылку , которую я сделал для одного экрана. Однако, мне трудно для нескольких экранов.Так, как бы я сделал это для нескольких экранов?
вот мой код
- (NSImage*) desktopAsImageWithScreen:(NSScreen *)screen {
NSDictionary *deviceDescription = [screen deviceDescription];
CFMutableArrayRef windowIDs = CFArrayCreateMutable(NULL, 0, NULL);
CFArrayRef allWindowIDs = CGWindowListCreate(kCGWindowListOptionOnScreenBelowWindow, kCGDesktopIconWindowLevel);
NSLog(@"min window level: %d", kCGMinimumWindowLevel);
NSLog( @"looking for windows on level: %d", kCGDesktopWindowLevel );
NSLog( @"NOt actually looking for windows on level: %d", kCGMinimumWindowLevel );
NSLog( @"NOt actually looking for windows on the dock level: %d", kCGDockWindowLevel );
if (allWindowIDs)
{
CFArrayRef windowDescs = CGWindowListCreateDescriptionFromArray(allWindowIDs);
for (CFIndex idx=0; idx<CFArrayGetCount(windowDescs); idx++)
{
CFDictionaryRef dict = CFArrayGetValueAtIndex(windowDescs, idx);
CFStringRef ownerName = CFDictionaryGetValue(dict, kCGWindowOwnerName);
NSLog(@"owner name = %@", ownerName);
if (CFStringCompare(ownerName, CFSTR("Dock"), 0) == kCFCompareEqualTo )
{
// the Dock level has the dock and the desktop picture
CGRect windowBounds;
BOOL success = CGRectMakeWithDictionaryRepresentation(
(CFDictionaryRef)(CFDictionaryGetValue(dict, kCGWindowBounds)),
&windowBounds);
NSRect screenBounds = screen.frame;
CFNumberRef windowLayer = CFDictionaryGetValue(dict, kCGWindowLayer);
//CFDictionaryGetValue(dict, kCGWindowBounds)
NSLog(@"window bounds %f, %f, matches screen bounds? %d, on level %@",
windowBounds.size.width,
windowBounds.size.height,
CGRectEqualToRect(windowBounds, screenBounds),
windowLayer
);
NSNumber* ourDesiredLevelNumber = [NSNumber numberWithInt: kCGDesktopWindowLevel - 1];
if ( CGRectEqualToRect(windowBounds, screenBounds) && [ourDesiredLevelNumber isEqualToNumber: (__bridge NSNumber * _Nonnull)(windowLayer)] )
CFArrayAppendValue(windowIDs, CFArrayGetValueAtIndex(allWindowIDs, idx));
}
}
CFRelease(windowDescs);
CFRelease(allWindowIDs);
}
CGImageRef cgImage = CGWindowListCreateImageFromArray( screen.frame, windowIDs, kCGWindowImageDefault);
// Create a bitmap rep from the image...
NSBitmapImageRep *bitmapRep = [[NSBitmapImageRep alloc] initWithCGImage:cgImage];
// Create an NSImage and add the bitmap rep to it...
NSImage *image = [[NSImage alloc] init];
[image addRepresentation:bitmapRep];
//[bitmapRep release];
return image;
}
Любые предложения?
Заранее спасибо!