Chinaunix首页 | 论坛 | 博客
  • 博客访问: 528889
  • 博文数量: 104
  • 博客积分: 2089
  • 博客等级: 大尉
  • 技术积分: 1691
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-29 08:48
文章分类

全部博文(104)

文章存档

2015年(1)

2013年(13)

2012年(31)

2011年(59)

分类: iOS平台

2013-11-28 20:06:57

mac 10.6.8 xcode 版本 3.2.6 桌面应用通过

截图代码

  1. static void savePNGImage(CGImageRef imageRef, NSString *path)
  2. {
  3.     
  4.    
  5.     NSURL *fileURL = [NSURL fileURLWithPath:path];
  6.     CGImageDestinationRef dr = CGImageDestinationCreateWithURL(( CFURLRef)fileURL, kUTTypePNG , 1, NULL);
  7.     
  8.     CGImageDestinationAddImage(dr, imageRef, NULL);
  9.     CGImageDestinationFinalize(dr);
  10.     
  11.     CFRelease(dr);
  12. }

  13. static void save()
  14. {
  15.     CGDirectDisplayID displayID = CGMainDisplayID();
  16.     CGImageRef imageRef = CGDisplayCreateImage(displayID);
  17.     
  18.     NSString *path = [@"~/Desktop/public.png" stringByExpandingTildeInPath];
  19.     NSLog(@"save file: %@", path);
  20.     savePNGImage(imageRef, path);
  21.     
  22.     CFRelease(imageRef);    
  23. }
按钮点击 调用 

  1. -(IBAction) btnScreenShot:(id) sender{
  2.     printf("screen short start\n");
  3.     save();
  4. }
关联事件后,触发后, 将在桌面保存 png 桌面截图







阅读(1695) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~