ios - PHImageManager 由于从照片库编辑而错误地获取照片

标签 ios objective-c iphone uiimage phasset

关于使用 PHImageManager 获取 UIImage,我遇到了一个奇怪的问题。

当请求的 UIImage 不是从 iPhone 的照片应用程序编辑时,一切正常;

[[PHImageManager defaultManager] requestImageForAsset:[assets objectAtIndex:0] targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeDefault options:requestOptions resultHandler:^void(UIImage *image, NSDictionary *info)
         {
             DebugLog(@"%ld", assets.count);
             @autoreleasepool
             {
                 if (image)
                 {
                     // Write image to system
                     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
                     NSString *fileName = [NSString stringWithFormat:@"%ld_%@.jpg", (long)assets.count, [NSDate date]];
                     NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:fileName];
                     [UIImageJPEGRepresentation(image, 0.5) writeToFile:filePath atomically:YES];

                 }
         }];

但是,如果用户从 iPhone 的自照片编辑器编辑照片(即她/他裁剪了照片),PHImageManager 将无法检索该照片。

没有编辑,resultHandler中提供的字典是正常的,叫做“info”:

{
PHImageFileOrientationKey = 0;
PHImageFileSandboxExtensionTokenKey = "5565e83d376d8c4e018b8ea41401e58e5aabbc18;00000000;00000000;000000000000001a;com.apple.app-sandbox.read;00000001;01000003;000000000039a762;/private/var/mobile/Media/DCIM/113APPLE/IMG_3433.PNG";
PHImageFileURLKey = "file:///var/mobile/Media/DCIM/113APPLE/IMG_3433.PNG";
PHImageFileUTIKey = "public.png";
PHImageResultDeliveredImageFormatKey = 9999;
PHImageResultIsDegradedKey = 0;
PHImageResultIsInCloudKey = 0;
PHImageResultIsPlaceholderKey = 0;
PHImageResultOptimizedForSharing = 0;
PHImageResultRequestIDKey = 55;
PHImageResultWantedImageFormatKey = 9999;

但是从照片应用程序编辑之后,字典变成了:

{
PHImageFileOrientationKey = 0;
PHImageResultDeliveredImageFormatKey = 4031;
PHImageResultIsDegradedKey = 1;
PHImageResultRequestIDKey = 56;
PHImageResultWantedImageFormatKey = 9998;

有没有人遇到过这个问题?

感谢您的回复。

最佳答案

好吧,我知道那里发生了什么。

在 PHImageRequestOptions 中有一个选项可以通过添加选择照片的未调整版本;

requestOptions.version = PHImageRequestOptionsVersionUnadjusted;

有了这个,我成功地得到了图像(但是是未调整的格式)。

任何人都可以在不调整图像的情况下找到进一步的解决方案,请评论我。

干杯。

关于ios - PHImageManager 由于从照片库编辑而错误地获取照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38455910/

相关文章:

ios - 每次我编译到设备时,Xcode 都会询问用户名和密码

ios - 创建自己的 UITableViewController

ios - 在 subview 中添加 UIViewController

iphone - 由 json 文件 iphone 制作的单层的 A* 寻路算法

iphone - UIPickerView 旋转效果

ios - 如何/在哪里声明用于编写objective-c代码的接口(interface)、实现、程序格式中的实例变量?

ios - 如何允许用户通过Siri在iOS应用中进行搜索

ios - NSOperationQueue NSOperation USER_INITIATED 崩溃

objective-c - 为什么 alloc 和 init 在 Objective-C 中分开调用?

iphone - 画图应用的 OpenGL ES 内容截图