- (void)makeScreenPicture {
[self.view lockFocus];
NSData * data = [self.view dataWithPDFInsideRect:self.view.bounds];
NSData* convertData = [[NSImage alloc]initWithData:data].TIFFRepresentation;
[self.view unlockFocus];
NSFileManager * fileMgr = [NSFileManager defaultManager];
NSString * path = @"/Users/yourName/Desktop/mytest.png";
[fileMgr createFileAtPath:pathcontents:convertData attributes:nil];
NSURL* fileUrl = [NSURL fileURLWithPath:path];
//截屏之后 在finder中打开.
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:@[fileUrl]];
}
网友评论