自iOS8以来,无法加载图像属性,如EXIF
我的代码在iOS7.x上运行得很好。但由于我是为iOS8编译的,它不再检索基本信息以外的其他信息。这是我现在得到的唯一信息,没有更多的日期、艺术家、模特等:自iOS8以来,无法加载图像属性,如EXIF,ios8,metadata,photo,Ios8,Metadata,Photo,我的代码在iOS7.x上运行得很好。但由于我是为iOS8编译的,它不再检索基本信息以外的其他信息。这是我现在得到的唯一信息,没有更多的日期、艺术家、模特等: { ColorModel = RGB; DPIHeight = 72; DPIWidth = 72; Depth = 8; Orientation = 1; PixelHeight = 2448; PixelWidth = 3264; "{Exif}" = {
{
ColorModel = RGB;
DPIHeight = 72;
DPIWidth = 72;
Depth = 8;
Orientation = 1;
PixelHeight = 2448;
PixelWidth = 3264;
"{Exif}" = {
ColorSpace = 1;
PixelXDimension = 3264;
PixelYDimension = 2448;
};
"{JFIF}" = {
DensityUnit = 1;
JFIFVersion = (
1,
0,
1
);
XDensity = 72;
YDensity = 72;
};
"{TIFF}" = {
Orientation = 1;
};
}
我的代码如下:
-(NSDictionary*)getExif:(NSURL*)assetURL asset:(ALAssetRepresentation *)image_representation {
// create a buffer to hold image data
uint8_t *buffer = (Byte*)malloc(image_representation.size);
NSUInteger length = [image_representation getBytes:buffer fromOffset: 0.0 length:image_representation.size error:nil];
if (length != 0) {
// buffer -> NSData object; free buffer afterwards
NSData *adata = [[NSData alloc] initWithBytesNoCopy:buffer length:image_representation.size freeWhenDone:YES];
// identify image type (jpeg, png, RAW file, ...) using UTI hint
NSDictionary* sourceOptionsDict = [NSDictionary dictionaryWithObjectsAndKeys:(id)[image_representation UTI],kCGImageSourceTypeIdentifierHint,nil];
// create CGImageSource with NSData
CGImageSourceRef sourceRef = CGImageSourceCreateWithData((__bridge CFDataRef) adata,
(__bridge CFDictionaryRef) sourceOptionsDict);
// get imagePropertiesDictionary
CFDictionaryRef imagePropertiesDictionary = CGImageSourceCopyPropertiesAtIndex(sourceRef,0, NULL);
NSLog(@"image props: %@",imagePropertiesDictionary);
CFDictionaryRef propsRef = (CFDictionaryRef)CFDictionaryGetValue(imagePropertiesDictionary, @"{TIFF}");
NSDictionary *props = (__bridge NSDictionary*)propsRef;
NSMutableDictionary *d = [[NSMutableDictionary alloc] init];
NSString * make = nil;
NSString *model = nil;
NSString *
s = [props objectForKey:@"DateTime" ]; if (s) [d setObject: s forKey:@"DateTime"];
s = [props objectForKey:@"Artist" ]; if (s) [d setObject:[s capitalizedString] forKey:@"Artist"];
s = make = [props objectForKey:@"Make" ]; if (s) [d setObject:s forKey:@"Make"];
s = model = [props objectForKey:@"Model" ]; if (s) {
if (make ) s = [s stringByReplacingOccurrencesOfString:make withString:@""];
[d setObject:s forKey:@"Model"];
}
// etc.
我认为这是Photos.Framework的一个bug。因为我在获取所有相集时可以获得完整的元数据,但在按集合获取相集时丢失了一些信息