mac _ Screenshots and screenshots
来源:互联网 发布:linux挂载光盘 编辑:程序博客网 时间:2024/05/29 13:25
由于项目需要,需要一个截图功能。
// 截屏(全屏幕)
- (IBAction)button1:(id)sender { NSMutableArray *datas = [NSMutableArray array]; //存储所有显示器显示id CGDirectDisplayID dspyIDArray[10]; uint32_t dspyIDCount = 0; //获取当前活跃的所有显示器id及其个数 if (CGGetActiveDisplayList(10, dspyIDArray, &dspyIDCount) != kCGErrorSuccess) return; CFStringRef dspyDestType = CFSTR("public.png"); for(uint32_t i = 0; i < dspyIDCount; i++) { CGDirectDisplayID mainID = dspyIDArray[i]; // 根据Quartz分配给显示器的id,生成显示器mainID的截图 CGImageRef mainCGImage = CGDisplayCreateImage(mainID); CFMutableDataRef mainMutData = CFDataCreateMutable(NULL, 0); CGImageDestinationRef mainDest = CGImageDestinationCreateWithData(mainMutData, dspyDestType, 1, NULL); CGImageDestinationAddImage(mainDest, mainCGImage, NULL); CGImageRelease(mainCGImage); CGImageDestinationFinalize(mainDest); CFRelease(mainDest); [datas addObject:(__bridge NSData *)mainMutData]; CFRelease(mainMutData); } CFRelease(dspyDestType); NSInteger imageCount = [datas count]; if (imageCount <= 0) { return; } NSImage *tmpImage = [[NSImage alloc] initWithData:[datas objectAtIndex:imageCount-1]]; [self.imageviews setImage:tmpImage];}
// 选取截图
- (IBAction)button2:(id)sender { NSTask *capture = [[NSTask alloc] init]; capture.launchPath = @"/usr/sbin/screencapture"; capture.arguments = [NSArray arrayWithObjects:@"-i", @"-c", nil]; [capture setTerminationHandler: ^(NSTask *t) { NSPasteboard *pboard = [NSPasteboard generalPasteboard]; if ([pboard pasteboardItems].count <= 0) return ; NSPasteboardItem *pboardItem = [[pboard pasteboardItems] objectAtIndex:0]; NSString *pboardItemType = [[pboard types] objectAtIndex:0]; NSData *imageData = [pboardItem dataForType:pboardItemType]; NSImage *image = [[NSImage alloc] initWithData:imageData]; [self.imageviews setImage:image]; }]; [capture launch];}
// 3
// 命令行选择性截屏- (IBAction)button3:(id)sender { NSTask *capture = [[NSTask alloc] init]; capture.launchPath = @"/usr/sbin/screencapture"; capture.arguments = [NSArray arrayWithObjects:@"-c", nil]; [capture setTerminationHandler:^(NSTask *t) { NSPasteboard *pboard = [NSPasteboard generalPasteboard]; NSPasteboardItem *pboardItem = [[pboard pasteboardItems] objectAtIndex:0]; NSString *pboardItemType = [[pboard types] objectAtIndex:0]; NSData *imageData = [pboardItem dataForType:pboardItemType]; NSImage *image = [[NSImage alloc] initWithData:imageData]; [self.imageviews setImage:image]; image = nil; }]; [capture launch];}
参考资料:http://blog.sina.com.cn/s/blog_8343bc050102vaud.html
阅读全文
0 0
- mac _ Screenshots and screenshots
- Taking Screenshots in Mac OS X
- Fedora7 Screenshots
- Capture screenshots on Mac 在Mac下截图
- 《Sikuli: Using GUI Screenshots for Search and Automation》
- Some screenshots of Fbx2Cal
- debian的screenshots
- How to make DirectFB screenshots
- How to Make Great App Store Screenshots
- Unity3D save ScreenShots by 3 methods
- Organizer截的Screenshots放在哪了?
- Take screenshots from the command line in Linux
- C++ » File » File Read Write Screenshots
- 解决iTunes connect上传后“Missing Localized Screenshots”错误
- How to detect screenshots on iOS (like SnapChat)
- How to take screenshots on your Samsung Galaxy Tab 10.1
- Failed to create a screenshot for Screenshots for 问题的解决办法
- Epic Games Shows Incredible New Anti-Aliasing Technique – Screenshots + Video Comparison
- 基于nghttp2的apns HTTP2 C++ 测试程序
- vim命令
- MySQL安装详解
- linux进程死锁
- bootstrap之仿淘宝商品列表
- mac _ Screenshots and screenshots
- 如何优化你的布局层级结构之RelativeLayout和LinearLayout及FrameLayout性能分析
- 多线程并发编程
- 修改git使用的远程仓库
- BZOJ 3052: [wc2013]糖果公园
- 世界各国Google网址大全
- python 排列组合
- 经典算法面试题(三):小猪吃米
- MATLAB中dither抖动函数的用法