记录一下:

 

- (void)save
{
    //把图片保存到系统相册
    //把UIView上面的绘制的内容生成一张图片.保存.
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    //把画板上的东西绘制到上下文当中
    [self.view.layer renderInContext:ctx];
    //从上下文当中生成一张图片
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    //关闭上下文
    UIGraphicsEndImageContext();
    //把生成的图片保存到系统相册
    //注意:保存图片成功必须得要调用下面方法.
    //    image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
    UIImageWriteToSavedPhotosAlbum(newImage, self, @selector(image:didFinishSavingWithError: contextInfo:), nil);
}

//保存图片成功时调用
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *) contextInfo
{    
    NSLog(@"保存完成");
}

 

相关文章:

  • 2021-12-23
  • 2022-12-23
  • 2021-11-01
  • 2021-12-17
  • 2021-08-15
  • 2021-08-05
猜你喜欢
  • 2021-08-04
  • 2022-01-07
  • 2022-12-23
  • 2021-12-05
  • 2021-08-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案