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

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(@"保存图片成功");

    }

}


©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容