码迷,mamicode.com
首页 > 其他好文 > 详细

截图代码

时间:2015-09-04 14:17:22      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:

截图代码

static void savePNGImage(CGImageRef imageRef, NSString *path)

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

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

按钮点击 调用 

  1. -(IBAction) btnScreenShot:(id) sender{
  2.     printf("screen short start\n");
  3.     save();
  4. }

关联事件后,触发后, 将在桌面保存 png 桌面截图

截图代码

标签:

原文地址:http://www.cnblogs.com/timdes/p/4781143.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!