相片中記載許多拍攝當時的資訊,那我們該如何去擷取相片資訊呢?如解析度、拍攝時間、拍攝地點、光圈、快門、品牌、機種等等。
首先在專案加入AssetsLibrary.framework,並在.m中#import <AssetsLibrary/AssetsLibrary.h>。
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
DLog(@"info:%@",info);
}
info列印出來會像這樣:
info:{ UIImagePickerControllerMediaType = “public.image"; UIImagePickerControllerOriginalImage = “<UIImage: 0x17e49ef0>"; UIImagePickerControllerReferenceURL = “assets-library://asset/asset.JPG?id=1C151E38-D4DD-444A-996C-9651803E508E&ext=JPG"; }
此時要使用ALAssetsLibrary追溯UIImagePickerControllerReferenceURL這個key,asset.defaultRepresentation.metadata即可取得相片資訊,。
ALAssetsLibrary *assetLibray = [[ALAssetsLibrary alloc] init];
[assetLibray assetForURL:[info objectForKey:@"UIImagePickerControllerReferenceURL"] resultBlock:^(ALAsset *asset){
DLog(@"metadata:%@",asset.defaultRepresentation.metadata);
} failureBlock:^(NSError *err){
DLog(@"err:%@",err);
}];
列印出來會像這樣:
metadata:{
ColorModel = RGB;
DPIHeight = 72;
DPIWidth = 72;
Depth = 8;
PixelHeight = 2048;
PixelWidth = 1536;
“{Exif}" = {
ApertureValue = “2.52606882168926″;
BrightnessValue = “3.007532956685499″;
ColorSpace = 1;
ComponentsConfiguration = (
1,
2,
3,
0
);
DateTimeDigitized = “2013:08:09 15:49:37″;
DateTimeOriginal = “2013:08:09 15:49:37″;
ExifVersion = (
2,
2,
1
);
ExposureMode = 0;
ExposureProgram = 2;
ExposureTime = “0.04166666666666666″;
FNumber = “2.4″;
Flash = 16;
FlashPixVersion = (
1,
0
);
FocalLenIn35mmFilm = 35;
FocalLength = “4.28″;
ISOSpeedRatings = (
50
);
LensMake = Apple;
LensModel = “iPhone 4S back camera 4.28mm f/2.4″;
LensSpecification = (
“4.28″,
“4.28″,
“2.4″,
“2.4″
);
MeteringMode = 5;
PixelXDimension = 3264;
PixelYDimension = 2448;
SceneCaptureType = 0;
SceneType = 1;
SensingMethod = 2;
ShutterSpeedValue = “4.584985835694051″;
SubjectArea = (
1631,
1223,
881,
881
);
SubsecTimeDigitized = 023;
SubsecTimeOriginal = 023;
WhiteBalance = 0;
};
“{GPS}" = {
Altitude = “34.84348395546824″;
AltitudeRef = 0;
DateStamp = “2013:08:09″;
Latitude = “25.01262221666667″;
LatitudeRef = N;
Longitude = “121.5152283333333″;
LongitudeRef = E;
TimeStamp = “07:49:34″;
};
“{MakerApple}" = {
1 = 0;
3 = {
epoch = 0;
flags = 1;
timescale = 1000000000;
value = 51254606438541;
};
4 = 1;
5 = 128;
6 = 126;
7 = 0;
};
“{TIFF}" = {
DateTime = “2013:08:09 15:49:37″;
Make = Apple;
Model = “iPhone 4S";
ResolutionUnit = 2;
Software = “7.0″;
XResolution = 72;
YResolution = 72;
};
}
得到的相片資訊相當多,可以有許多方向使用。
參考:使用 AssetsLibrary 取得圖庫中檔案的相關資訊、how to get the data from UIImagePickerControllerReferenceURL iOS Sdk。
隨意留個言吧:)~