码迷,mamicode.com
首页 > 移动开发 > 详细

iOS屏幕截屏

时间:2016-06-26 18:14:24      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    //开启位图上下文
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0);
    //获取上下文
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    //把控件上的图层渲染到上下文(图层只能渲染不能绘制)
    [self.view.layer renderInContext:ctx];
    //生产一张图片
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    //关闭上下文
    UIGraphicsEndImageContext();
    //把图片转化成二进制PNG
    NSData *imageData = UIImagePNGRepresentation(image);
    //写入到桌面
    [imageData writeToFile:@"/Users/zhaotian/Desktop/view.png" atomically:YES];
  
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

  

iOS屏幕截屏

标签:

原文地址:http://www.cnblogs.com/TianHero/p/5618110.html

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