iOS屏幕截屏
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS屏幕截屏相关的知识,希望对你有一定的参考价值。
#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屏幕截屏的主要内容,如果未能解决你的问题,请参考以下文章