ios - 图片库图片网址“assets-library://asset/asset.JPG?id = 1000000007&ext = JPG”为零

标签 ios objective-c ipad

我想从iPad的照片库中获取图像URL。

当我尝试从Image Piicker的信息中获取 UIImagePickerControllerReferenceURL
我将URL设为:

 assets-library://asset/asset.JPG?id=1000000007&ext=JPG

因为我想获取图像元数据(image height,width and size in MB)而不加载到内存中。

我尝试下面的代码:
 -(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
    {
        NSURL *mediaURL;
        mediaURL=(NSURL*)[info valueForKey:UIImagePickerControllerMediaURL];
        NSURL *imageFileURL = (NSURL*)[info valueForKey:UIImagePickerControllerReferenceURL];

        NSLog(@" referenURL %@  mediaURL %@" ,imageFileURL,mediaURL);

        //We can get Image property from imagepath.
        //NSURL *imageFileURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@",_directoryPath,roomImageNames[i]]];
        CGImageSourceRef imageSource = CGImageSourceCreateWithURL((__bridge CFURLRef)imageFileURL, NULL);
        NSDictionary *properties = (__bridge_transfer NSDictionary *)CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL);

        CGFloat height = [[properties objectForKey:@"PixelHeight"] floatValue];
        CGFloat width = [[properties objectForKey:@"PixelWidth"] floatValue];
        NSLog(@"height %f  width  %f",height ,width);
}

我得到的图像高度和宽度为0.0

让我知道我做错了什么。

最佳答案

在iOS8之后,您应该使用Photos.framework访问系统照片库。

单个照片模型是PHAsset实例对象。它具有pixelWidthpixelHeight属性,用于存储当前照片的尺寸信息。通过这些信息,您可以计算其内存大小。

关于ios - 图片库图片网址“assets-library://asset/asset.JPG?id = 1000000007&ext = JPG”为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42197786/

相关文章:

iphone - 如何在基于导航的 iOS 应用程序中访问比当前 View 上一级的 View ?

iphone - 代码签名错误 : Certificate identity 'iPhone Developer: My Name (xxx)' appears more than once in the keychain

ios - 从 UITableViewCell : addChildViewController unrecognized selector sent to instance 呈现 UIViewController

objective-c - "import <XYZ/XYZ.h>"是什么意思

objective-c - ld : duplicate symbol - caused by const

iphone - 从主线程或网页线程以外的线程获取网页锁。不应从辅助线程调用 UIKit

ios - UIPopover 获取屏幕上的确切位置

ios - 在 ios 7 中启用编辑时,UITableViewCell subview 不移动

ios - Firebase 的 Swift 中的 SetValue 删除了旧值

ios - [UILabel numberOfComponentsInPickerView :]: unrecognized selector sent to instance . ..]