IOS截取屏幕到文件中
2018-07-20 来源:open-open
在这里首先明确,View中显示的东西都在在layer中的。
我们通过renderInContext来渲染layer中的内容
- (void)viewDidLoad {
[super viewDidLoad];
//截取当前的View
//1.创建图层
UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, 0.0);
//2.渲染layer
CGContextRef ctr = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:ctr];
CGContextStrokePath(ctr);
//3.取出image
UIImage *imageNew = UIGraphicsGetImageFromCurrentImageContext();
//4.关闭图层
UIGraphicsEndImageContext();
//5.将图片转换成NSData
NSData *data = UIImagePNGRepresentation(imageNew);
[data writeToFile:@"/Users/misaka/Desktop/1.png" atomically:YES];
// Do any additional setup after loading the view, typically from a nib.
}
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
最新资讯
热门推荐