iOS AssetsLibrary和Photos的使用总结(2): 原图获取
来源:互联网 发布:软件测试难不难 编辑:程序博客网 时间:2024/04/30 18:57
源码下载:https://github.com/darling0825/DLPhotoPicker.git
封装了AssetsLibrary和Photos的API,支持iOS7和iOS8以上
- (UIImage *)originImage{ @autoreleasepool { if (_originImage) { return _originImage; } __block UIImage *resultImage; if (UsePhotoKit) { // image after edited PHImageRequestOptions *originRequestOptions = [[PHImageRequestOptions alloc] init]; originRequestOptions.version = PHImageRequestOptionsVersionCurrent; originRequestOptions.networkAccessAllowed = YES; originRequestOptions.synchronous = YES; //sync requests are automatically processed this way regardless of the specified mode //originRequestOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat; originRequestOptions.progressHandler = ^(double progress, NSError *__nullable error, BOOL *stop, NSDictionary *__nullable info){ dispatch_main_async_safe(^{ }); }; [[[DLPhotoManager sharedInstance] phCachingImageManager] requestImageForAsset:self.phAsset targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeDefault options:originRequestOptions resultHandler:^(UIImage *result, NSDictionary *info) { @autoreleasepool { BOOL downloadFinined = ![[info objectForKey:PHImageCancelledKey] boolValue] && ![info objectForKey:PHImageErrorKey] && ![[info objectForKey:PHImageResultIsDegradedKey] boolValue] && result; if (downloadFinined) { resultImage = result; } } ]; } else { CGImageRef fullResolutionImageRef = [[self.alAsset defaultRepresentation] fullResolutionImage]; NSString *adjustment = [[[self.alAsset defaultRepresentation] metadata] objectForKey:@"AdjustmentXMP"]; if (adjustment) { NSData *xmpData = [adjustment dataUsingEncoding:NSUTF8StringEncoding]; CIImage *tempImage = [CIImage imageWithCGImage:fullResolutionImageRef]; NSError *error; NSArray *filterArray = [CIFilter filterArrayFromSerializedXMP:xmpData inputImageExtent:tempImage.extent error:&error]; CIContext *context = [CIContext contextWithOptions:nil]; if (filterArray && !error) { for (CIFilter *filter in filterArray) { [filter setValue:tempImage forKey:kCIInputImageKey]; tempImage = [filter outputImage]; } fullResolutionImageRef = [context createCGImage:tempImage fromRect:[tempImage extent]]; } } resultImage = [UIImage imageWithCGImage:fullResolutionImageRef scale:[[self.alAsset defaultRepresentation] scale] orientation:(UIImageOrientation)[[self.alAsset defaultRepresentation] orientation]]; } _originImage = resultImage; return resultImage; }}- (NSInteger)requestOriginImageWithCompletion:(void (^)(UIImage *, NSDictionary *))completion withProgressHandler:(PHAssetImageProgressHandler)phProgressHandler{ @autoreleasepool { if (UsePhotoKit) { if (_originImage) { dispatch_main_async_safe(^{ if (completion) { completion(_originImage, nil); } }) return 0; } else { PHImageRequestOptions *originRequestOptions = [[PHImageRequestOptions alloc] init]; originRequestOptions.version = PHImageRequestOptionsVersionCurrent; originRequestOptions.networkAccessAllowed = YES; originRequestOptions.progressHandler = phProgressHandler; self.imageRequestID = [[[DLPhotoManager sharedInstance] phCachingImageManager] requestImageForAsset:self.phAsset targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeDefault options:originRequestOptions resultHandler:^(UIImage *result, NSDictionary *info) { BOOL downloadFinined = ![[info objectForKey:PHImageCancelledKey] boolValue] && ![info objectForKey:PHImageErrorKey] && ![[info objectForKey:PHImageResultIsDegradedKey] boolValue]; if (downloadFinined) { _originImage = result; } if (completion) { completion(result, info); } } }]; return self.imageRequestID; } } else { dispatch_main_async_safe(^{ if (completion) { completion([self originImage], nil); } }) return 0; } }}
0 0
- iOS AssetsLibrary和Photos的使用总结(2): 原图获取
- iOS AssetsLibrary和Photos的使用总结(1): 权限及相册的获取
- iOS<Photos/Photos.h>与<AssetsLibrary/AssetsLibrary.h>and 相机
- IOS AssetsLibrary框架的使用
- IOS AssetsLibrary框架的使用
- iOS 获取相册原图
- iOS Photos.framework 使用
- iOS开发AssetsLibrary的介绍
- 浅谈关于AssetsLibrary和PhotoKit的使用
- iOS相册实现与AssetsLibrary框架使用
- AssetsLibrary/AssetsLibrary.h 相册获取
- iOS:<Photos/Photos.h>获取相册视频以及图片
- iOS的AssetsLibrary框架访问所有相片
- iOS的AssetsLibrary框架访问所有相片
- iOS的AssetsLibrary框架访问所有相片
- iOS的AssetsLibrary框架解读与应用
- iOS的AssetsLibrary框架访问所有相片
- iOS的AssetsLibrary框架访问所有相片
- Spring注解配置定时任务<task:annotation-driven/>
- Hibernate三态
- iOS支持MP4,AVI,NAVI,DV-AVI,DIVX,MOV,ASF,WMV,RM,RMVB等视频格式。
- Android静默安装和静默卸载
- 最流行的android组件大全
- iOS AssetsLibrary和Photos的使用总结(2): 原图获取
- Trick(五)——交换两个数(swap)
- C++Primer第5版读书笔记(第6章)
- nginx使用ssl模块配置HTTPS支持
- 按键事件笔记
- 输入数字,输出数字读法
- 88. Merge Sorted Array
- Android基于Facebook Rebound的动画效果框架Backboard demo (非常炫酷)
- LINUX右键菜单当前路径打开终端