我想从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
实例对象。它具有pixelWidth
和pixelHeight
属性,用于存储当前照片的尺寸信息。通过这些信息,您可以计算其内存大小。
关于ios - 图片库图片网址“assets-library://asset/asset.JPG?id = 1000000007&ext = JPG”为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42197786/