UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
上面的方法截出来的图很模糊,建议使用下面的方法
//opaque 透明度,不透明设为YES;
//scale 缩放因子,设0时系统自动设置缩放比例图片清晰;设1.0时模糊
UIGraphicsBeginImageContextWithOptions(_posterView.size,YES,0.0);
[_posterView.layerrenderInContext:UIGraphicsGetCurrentContext()];
UIImage*image =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(image, self,@selector(image:didFinishSavingWithError:contextInfo:), nil);