[英]How can I retrieve a photo's file size using ALAssetsLibrary?
I'm trying to retrieve relevant metadata for a photo using ALAssetsLibrary
. 我正在尝试使用
ALAssetsLibrary
检索照片的相关元数据。 The below code works perfectly for all data except file size - kCGImagePropertyFileSize
. 以下代码对文件大小
kCGImagePropertyFileSize
以外的所有数据均kCGImagePropertyFileSize
。 Also, how can I retrieve the image format? 另外,如何检索图像格式?
Thanks. 谢谢。
[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) {
}];
long long dataSize = [asset.defaultRepresentation size];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.