美文网首页
iOS--将图片保存至本地相册

iOS--将图片保存至本地相册

作者: 缘來諟夢 | 来源:发表于2020-05-19 09:33 被阅读0次
//步骤一:
/**
*  将图片添加到本地相册
*/
- (void)addImageViewTolocal{
    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:imgStr]];
    UIImage *myImage = [UIImage imageWithData:data];
    [self saveImageToPhotos:myImage];
}
//步骤二:
- (void)saveImageToPhotos:(UIImage*)savedImage
{
    UIImageWriteToSavedPhotosAlbum(savedImage, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
}
//步骤三:
- (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void*) contextInfo
{
    NSString *msg = nil ;
    if(error != NULL){
        msg =@"保存图片失败" ;
    }else{
        msg =@"保存图片成功" ;
        
    }
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"保存图片结果提示"
                                                    message:msg
                                                   delegate:self
                                          cancelButtonTitle:@"确定"
                                          otherButtonTitles:nil];
    [alert show];
}

相关文章

网友评论

      本文标题:iOS--将图片保存至本地相册

      本文链接:https://www.haomeiwen.com/subject/rksvohtx.html