我尝试使用ALAssetsLibrary
检索照片的相关元数据。以下代码适用于除文件大小 - kCGImagePropertyFileSize
以外的所有数据。另外,我该如何检索图像格式?
感谢。
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
[group setAssetsFilter:[ALAssetsFilter allAssets]];
[group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:photoNumber] options:0 usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {
if (alAsset) {
if ([[alAsset valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]){
ALAssetRepresentation *representation = [alAsset defaultRepresentation];
NSDictionary *imageMetadata = [representation metadata];
NSDictionary *tiffDictionary = [imageMetadata objectForKey:(NSString *)kCGImagePropertyTIFFDictionary];
NSString *cameraMake = [tiffDictionary objectForKey:(NSString *)kCGImagePropertyTIFFMake];
NSString *cameraModel = [tiffDictionary objectForKey:(NSString *)kCGImagePropertyTIFFModel];
NSString *cameraSoftware = [tiffDictionary objectForKey:(NSString *)kCGImagePropertyTIFFSoftware];
NSString *photoCopyright = [tiffDictionary objectForKey:(NSString *)kCGImagePropertyTIFFCopyright];
NSDictionary *exifDictionary = [imageMetadata objectForKey:(NSString *)kCGImagePropertyExifDictionary];
NSString *lensMake = [exifDictionary objectForKey:(NSString *)kCGImagePropertyExifLensMake];
NSString *lensModel = [exifDictionary objectForKey:(NSString *)kCGImagePropertyExifLensModel];
NSString *exposureTime = [exifDictionary objectForKey:(NSString *)kCGImagePropertyExifExposureTime];
NSString *exposureProgram = [exifDictionary objectForKey:(NSString *)kCGImagePropertyExifExposureProgram];
NSString *ISOSpeed = [exifDictionary objectForKey:(NSString *)kCGImagePropertyExifISOSpeedRatings];
NSString *dateTime = [exifDictionary objectForKey:(NSString *)kCGImagePropertyExifDateTimeOriginal];
NSString *shutterSpeed = [exifDictionary objectForKey:(NSString *)kCGImagePropertyExifShutterSpeedValue];
NSString *apertureValue = [exifDictionary objectForKey:(NSString *)kCGImagePropertyExifApertureValue];
NSString *focalLength = [exifDictionary objectForKey:(NSString *)kCGImagePropertyExifFocalLength];
NSString *whiteBalance = [exifDictionary objectForKey:(NSString *)kCGImagePropertyExifWhiteBalance];
NSString *photoSize = [imageMetadata objectForKey:(NSString *)kCGImagePropertyFileSize];
NSString *photoWidth = [imageMetadata objectForKey:(NSString *)kCGImagePropertyPixelWidth];
NSString *photoHeight = [imageMetadata objectForKey:(NSString *)kCGImagePropertyPixelHeight];
NSDictionary *gpsDictionary = [imageMetadata objectForKey:(NSString *)kCGImagePropertyGPSDictionary];
NSString *gpsLatitude = [gpsDictionary objectForKey:(NSString *)kCGImagePropertyGPSLatitude];
NSString *gpsLatitudeRef = [gpsDictionary objectForKey:(NSString *)kCGImagePropertyGPSLatitudeRef];
NSString *gpsLongitude = [gpsDictionary objectForKey:(NSString *)kCGImagePropertyGPSLongitude];
NSString *gpsLongitudeRef = [gpsDictionary objectForKey:(NSString *)kCGImagePropertyGPSLongitudeRef];
NSLog(@"MAKE = %@", cameraMake);
NSLog(@"MODEL = %@", cameraModel);
NSLog(@"SOFTWARE = %@", cameraSoftware);
NSLog(@"COPYRIGHT = %@", photoCopyright);
NSLog(@"LENS MAKE = %@", lensMake);
NSLog(@"LENS MODEL = %@", lensModel);
NSLog(@"EXPOSURE TIME = %@", exposureTime);
NSLog(@"EXPOSURE PROGRAM = %@", exposureProgram);
NSLog(@"ISO SPEED = %@", ISOSpeed);
NSLog(@"DATE & TIME = %@", dateTime);
NSLog(@"SHUTTER SPEED = %@", shutterSpeed);
NSLog(@"APERTURE VALUE = %@", apertureValue);
NSLog(@"FOCAL LENGTH = %@", focalLength);
NSLog(@"WHITE BALANCE = %@", whiteBalance);
NSLog(@"IMAGE SIZE = %@", photoSize);
NSLog(@"IMAGE WIDTH = %@", photoWidth);
NSLog(@"IMAGE HEIGHT = %@", photoHeight);
NSLog(@"GPS Coordinates: %@ %@ / %@ %@", gpsLatitude, gpsLatitudeRef, gpsLongitude, gpsLongitudeRef);
}
else if([[alAsset valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo]){
}
}
}];
}
failureBlock: ^(NSError *error2) {
}];
答案 0 :(得分:2)
long long dataSize = [asset.defaultRepresentation size];