Mac截图

//截图 原点从左上角开始
// NSRect rect = [self.view convertRect:self.view.frame toView:nil];
// HSMainWindowCtr mainWc = [(HSAppDelegate)[NSApplication sharedApplication].delegate mainWindowCtr];
// rect.origin.y += 63;
// CFArrayRef windowsRef = CGWindowListCreate(kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
// CGImageRef imgRef = CGWindowListCreateImageFromArray(rect, windowsRef, kCGWindowImageNominalResolution);
// CFRelease(windowsRef);
// _scrshotImage = [[NSImage alloc] initWithCGImage:imgRef size:CGSizeZero];
// CGImageRelease(imgRef);

NSRect rect = [NSScreen mainScreen].frame;
NSRect subRect = [(HSAppDelegate*)[NSApplication sharedApplication].delegate window].frame;
subRect.origin.x += 60;
subRect.size.width -= 60;
subRect.origin.y = NSHeight(rect) - NSMaxY(subRect) + 71;
subRect.size.height -= 101;
CGImageRef screenShot = CGWindowListCreateImage(subRect, kCGWindowListExcludeDesktopElements, kCGNullWindowID, kCGWindowImageNominalResolution);
_scrshotImage = [[NSImage alloc] initWithCGImage:screenShot size:subRect.size];
CGImageRelease(screenShot);

NSSize size = NSMakeSize(200, 125);
NSImage *image = [self resizeImage2:_scrshotImage forSize:size];

[self.panelModuleWc showWindow:nil];
[self.panelModuleWc.window setLevel:NSNormalWindowLevel + 1];
[self.panelModuleWc.window makeKeyWindow];
self.panelModuleWc.imgView.image = image;
[self.panelModuleWc.window center];
self.panelModuleWc.textFiled.stringValue = panelId;
[self.panelModuleWc.textFiled selectText:self.panelModuleWc.textFiled.stringValue];

你可能感兴趣的:(Mac截图)