[关闭]
@kingw 2016-04-20T23:43:43.000000Z 字数 589 阅读 1971

ios截屏并保存到相册

CALayer 截图 相册: ios


  1. - (IBAction)btnClick:(UIButton *)sender {
  2. UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, 0);
  3. CGContextRef ctx = UIGraphicsGetCurrentContext();
  4. // 将要保存的view绘制到上下文中
  5. [self.view.layer renderInContext:ctx];
  6. UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
  7. UIGraphicsEndImageContext();
  8. // 将图片保存到相册
  9. UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
  10. }
  11. // 图片保存到相册掉用,固定写法
  12. - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
  13. if (error) {
  14. NSLog(@"保存失败");
  15. }else{
  16. NSLog(@"保存成功");
  17. }
  18. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注