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) {
}];