iOS 保存系统相册并获取路径

Mark一个需求,将图片保存至系统相册,并获取保存路径,查看文档发现ALAssetsLibrary具有这个功能

 ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];

UIImage *saveImage = [UIImage imageNamed:@"xxxx"];   

[assetLibrary writeImageToSavedPhotosAlbum:saveImage.CGImage metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) {        NSLog(@"assetURL = %@\n error = %@", assetURL, error);

}];

    

同样可以根据图片的路径获取图片

 __blockUIImage*targetImage;

 ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];    [assetLibrary assetForURL:[NSURL URLWithString:@"xxxxx"] resultBlock:^(ALAsset *asset) {

        ALAssetRepresentation *assetRep = [asset defaultRepresentation];

        CGImageRef imgRef = [assetRepfullResolutionImage];

        targetImage = [UIImage imageWithCGImage:imgRef

                                           scale:assetRep.scale

                                     orientation:(UIImageOrientation)assetRep.orientation];

    }failureBlock:^(NSError*error) {

    }];

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