简体   繁体   English

如何使用ALAssetsLibrary检索照片的文件大小?

[英]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.

相关问题 保存前如何检查文件(视频)是否已经在ALAssetsLibrary(相册)中? - how to check if a file ( video) is already in ALAssetsLibrary (photo album ) before saving it? 如何将图像文件从iOS Photo Library(ALAssetsLibrary)复制到App的本地目录? - How to copy an image file from iOS Photo Library (ALAssetsLibrary) to the local directory of an App? 如何使用WKWebView检索文件? - How can I retrieve a file using WKWebView? 尝试使用ALAssetsLibrary检索一组照片 - Trying to retrieve a set of photos using ALAssetsLibrary 如何使用ALAssetsLibrary仅获取视频 - How do i get only the videos using ALAssetsLibrary 使用ALAssetsLibrary的writeImageToSavedPhotosAlbum:metadata:completionBlock复制照片:更改图像方向 - Copying a photo with ALAssetsLibrary's writeImageToSavedPhotosAlbum:metadata:completionBlock: changes image orientation 如何找到iPhone相机照片的尺寸,如何调整尺寸? - How to find the size of iphone camera photo and how can I resize it? 使用ALAssetsLibrary在某些设备中照片库显示为空 - Photo library display empty in some devices using ALAssetsLibrary 使用ALAssetsLibrary的空白相册会导致UIButton被隐藏 - Empty photo album using ALAssetsLibrary causes UIButton to be hidden 使用ALAssetsLibrary将照片多次保存到图库会导致崩溃 - Saving photo to library more than once using ALAssetsLibrary causes crash
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM