美文网首页
把URL图片直接保存到相册中

把URL图片直接保存到相册中

作者: 梁苏珍 | 来源:发表于2018-01-19 11:39 被阅读0次

UIImageView *gtp = [[UIImageView alloc] init];

    [gtp sd_setImageWithURL:[NSURL URLWithString:@"https://wx1.sinaimg.cn/mw690/00632esply1fnloc9x8fgj31kw16ou0y.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder"]];

    [gtp sd_setImageWithPreviousCachedImageWithURL:[NSURL URLWithString:@"https://wx1.sinaimg.cn/mw690/00632esply1fnloc9x8fgj31kw16ou0y.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder"] options:SDWebImageCacheMemoryOnly progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {

        NSLog(@"已接收%f,总大小%ld",(CGFloat)receivedSize,(long)expectedSize);

    } completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {

        //url加载完 在保存图片

        UIImageWriteToSavedPhotosAlbum(gtp.image, self, @selector(savedPhotoImage:didFinishSavingWithError:contextInfo:), nil);

    }];

//保存完成后调用的方法

- (void)savedPhotoImage:(UIImage*)image didFinishSavingWithError: (NSError *)error contextInfo: (void *)contextInfo {

    if (error) {

        NSLog(@"保存图片出错%@", error.localizedDescription);

    }

    else {

        NSLog(@"保存图片成功");

    }

}

相关文章

网友评论

      本文标题:把URL图片直接保存到相册中

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