- (void)captureView {
// 1.创建一个bitmap的上下文
UIGraphicsBeginImageContext(self.view.frame.size);
// 2.将屏幕绘制到上下文中
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
// 3.从上下文中取出绘制好的图片
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
NSData *data = UIImagePNGRepresentation(newImage);
//保存图片到文件夹中
NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject] stringByAppendingPathComponent:@"abc.png"];
[data writeToFile:path atomically:YES];
// 4.保存图片到相册
UIImageWriteToSavedPhotosAlbum(newImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
if (error) {
NSLog(@"保存失败");
}else
{
NSLog(@"保存成功");
}
}