最奇怪的事情正在发生。我有一个操作表,让用户可以选择用相机拍照或从相机胶卷中选择一个。在UIImagePicker从选择返回后,我使用ALAssetsLibrary来确定嵌入在照片中的GPS信息。从相机胶卷中选择照片效果很好,我可以检索GPS信息。但是,用相机拍照绝对没有提供GPS信息,实际上我根本没有元数据。有谁知道我在这里做错了什么?
以下代码:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if([mediaType isEqualToString:(__bridge NSString *)kUTTypeImage])
{
void (^ALAssetsLibraryAssetForURLResultBlock)(ALAsset *) = ^(ALAsset *asset)
{
// get images metadata
NSDictionary *metadata = asset.defaultRepresentation.metadata;
NSLog(@"Image Meta Data: %@",metadata);
// get coords
CLLocation *location = [asset valueForProperty:ALAssetPropertyLocation];
NSLog(@"coordLat: %f , coordLon: %f", location.coordinate.latitude, location.coordinate.longitude);
// do more here - rest of code snipped to keep this question short
};
NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:assetURL
resultBlock:ALAssetsLibraryAssetForURLResultBlock
failureBlock:^(NSError *error)
{
// handle error
}];
// rest of code snipped to keep this question short
正如我所解释的,使用相机时会输出以下内容。
2012-04-15 17:58:28.032 MyApp[511:707] Image Meta Data: (null)
2012-04-15 17:58:28.041 MyApp[511:707] coordLat: 0.000000 , coordLon: 0.000000
但是,如果我选择现有照片,或退出应用程序,请使用相机拍摄新照片,然后返回应用程序并从相机胶卷中选择该照片我从NSLog获得以下输出。< / p>
2012-04-15 17:57:03.286 MyApp[511:707] Image Meta Data: {
ColorModel = RGB;
DPIHeight = 72;
DPIWidth = 72;
Depth = 8;
Orientation = 6;
PixelHeight = 1936;
PixelWidth = 2592;
"{Exif}" = {
ApertureValue = "2.970854";
BrightnessValue = "2.886456";
ColorSpace = 1;
ComponentsConfiguration = (
1,
2,
3,
0
);
DateTimeDigitized = "2012:04:15 17:24:02";
DateTimeOriginal = "2012:04:15 17:24:02";
ExifVersion = (
2,
2,
1
);
ExposureMode = 0;
ExposureProgram = 2;
ExposureTime = "0.06666667";
FNumber = "2.8";
Flash = 24;
FlashPixVersion = (
1,
0
);
FocalLength = "3.85";
ISOSpeedRatings = (
80
);
MeteringMode = 5;
PixelXDimension = 2592;
PixelYDimension = 1936;
SceneCaptureType = 0;
SensingMethod = 2;
Sharpness = 2;
ShutterSpeedValue = "3.9112";
SubjectArea = (
1295,
967,
699,
696
);
WhiteBalance = 0;
};
"{GPS}" = {
Altitude = "14.9281";
AltitudeRef = 0;
ImgDirection = "107.4554";
ImgDirectionRef = T;
Latitude = "32.7366666666667";
LatitudeRef = N;
Longitude = "71.679";
LongitudeRef = W;
TimeStamp = "21:26:20.00";
};
"{TIFF}" = {
DateTime = "2012:04:15 17:24:02";
Make = Apple;
Model = "iPhone 4";
Orientation = 6;
ResolutionUnit = 2;
Software = "5.0.1";
XResolution = 72;
YResolution = 72;
"_YCbCrPositioning" = 1;
};
}
2012-04-15 17:57:03.302 MyApp[511:707] coordLat: 32.7366666666667 , coordLon: -71.679
PS - 我正在使用xCode 4.3 w / ARC
答案 0 :(得分:13)
在- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
保存照片时尝试此操作
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:image.CGImage
metadata:[info objectForKey:UIImagePickerControllerMediaMetadata]
completionBlock:^(NSURL *assetURL, NSError *error) {
NSLog(@"assetURL %@", assetURL);
}];
答案 1 :(得分:0)
@ Thanh-Cong Vo关于如何将图像保存到相册是正确的。看看关于将图像保存到相册的Apples documents说了什么
要将静止图像保存到用户的相机胶卷相册,请调用 UIImageWriteToSavedPhotosAlbum 功能来自于身体内部 imagePickerController:didFinishPickingMediaWithInfo: 方法。保存一个 电影到用户的相机胶卷相册,而不是调用 UISaveVideoAtPathToSavedPhotosAlbum 功能。这些功能, 在UIKit Function Reference中描述,仅保存图像或电影; 他们不保存元数据。
从iOS 4.0开始,您可以保存静态图像元数据,以及 静止图像,到相机胶卷。为此,请使用 writeImageToSavedPhotosAlbum:metadata:completionBlock: 的方法 资产库框架。请参阅说明 UIImagePickerControllerMediaMetadata密钥。