iOS 保存图片到相册, 保存到指定的路径

代码很简单只有一句话

不多说上代码:

<span style="font-size:24px;">UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    
    // 保存图片到指定的路径
    NSData *data = UIImagePNGRepresentation(newImage);
    [data writeToFile:@"/Users/userName/Desktop/myShaoNv.png" atomically:YES];
    </span>

<span style="font-size:24px;"> // 保存image 到相册中
    UIImageWriteToSavedPhotosAlbum(newImage, self, @selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:), nil);
    

// 保存到相册的代理方法, 判断保存的结果是否成功还是失败的信息
// 实现imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:
- (void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    NSString *message = @"保存照片";
    if (!error) {
        message = @"保存成功";
        
    } else
    {
        message = [error description];
    }
    NSLog(@"message is %@", message);
}
</span>


你可能感兴趣的:(ios,图片,图形)