用相机拍摄的照片不包含任何ALAsset元(Photo taken with camera does

2019-06-23 15:54发布

最怪异的事情正在发生。 我有一个动作片,其向用户提供了选择,要么使用相机拍摄的照片或选择从相机胶卷。 一旦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以下输出照片。

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 - 我使用的Xcode4.3瓦特/ ARC

Answer 1:

- (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);
    }];


Answer 2:

@青聪VO是正确的关于如何将图像保存到相册。 看看有什么说苹果的文件如何保存图像相册

要保存静止图像到用户的相机胶卷专辑,叫UIImageWriteToSavedPhotosAlbum从体内功能didFinishPickingMediaWithInfo:imagePickerController方法。 要将电影保存到用户的相机胶卷专辑,而不是调用UISaveVideoAtPathToSavedPhotosAlbum功能。 这些功能,在所描述的UIKit函数参考 , 保存图像或仅电影; 他们不保存元数据。

在IOS 4.0开始,你可以保存静止图像的元数据,与静止图像一起,在相机胶卷。 要做到这一点,使用writeImageToSavedPhotosAlbum:元数据:completionBlock:资产库框架的方法。 请参阅下面的描述UIImagePickerControllerMediaMetadata关键。



文章来源: Photo taken with camera does not contain any ALAsset metadata