0

通过以下步骤,我设法将 GPS 坐标添加到元数据:

  1. 从 UIImagePickerControllerSourceTypeCamera 检索 UIIMage
  2. writeImageToSavedPhotosAlbum使用地理定位元数据保存到磁盘 ( )
  3. 从磁盘读取ALAsset并将其转换为 jpegNSData

我可以在没有保存/读取磁盘的麻烦的情况下做同样的事情吗?

4

2 回答 2

1

UIImagePickerControllerDelegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [self dismissModalViewControllerAnimated:YES];

    [Utils ifLocationEnabledDo:^{
        switch (picker.sourceType) {
            case UIImagePickerControllerSourceTypeCamera:
            {   
                UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
                NSMutableDictionary *metadata = [[NSMutableDictionary alloc] initWithDictionary:[info objectForKey:UIImagePickerControllerMediaMetadata]];
                [Utils setLocation:metadata location:[SharedAppDelegate getCurrentLocation]];
                [[Utils getAssetsLibrary] writeImageDataToSavedPhotosAlbum:image metadata:metadata completionBlock:nil];
            }
                break;
            default:
                break;
        }
    }];
}

在我的Utils课堂上:

+ (void)setLocation:(NSMutableDictionary *)metadata location:(CLLocation *)location
{

    if (location) {

        CLLocationDegrees exifLatitude  = location.coordinate.latitude;
        CLLocationDegrees exifLongitude = location.coordinate.longitude;

        NSString *latRef;
        NSString *lngRef;
        if (exifLatitude < 0.0) {
            exifLatitude = exifLatitude * -1.0f;
            latRef = @"S";
        } else {
            latRef = @"N";
        }

        if (exifLongitude < 0.0) {
            exifLongitude = exifLongitude * -1.0f;
            lngRef = @"W";
        } else {
            lngRef = @"E";
        }

        NSMutableDictionary *locDict = [[NSMutableDictionary alloc] init];
        if ([metadata objectForKey:(NSString*)kCGImagePropertyGPSDictionary]) {
            [locDict addEntriesFromDictionary:[metadata objectForKey:(NSString*)kCGImagePropertyGPSDictionary]];
        }
        [locDict setObject:[self getUTCFormattedDate:location.timestamp] forKey:(NSString*)kCGImagePropertyGPSTimeStamp];
        [locDict setObject:latRef forKey:(NSString*)kCGImagePropertyGPSLatitudeRef];
        [locDict setObject:[NSNumber numberWithFloat:exifLatitude] forKey:(NSString*)kCGImagePropertyGPSLatitude];
        [locDict setObject:lngRef forKey:(NSString*)kCGImagePropertyGPSLongitudeRef];
        [locDict setObject:[NSNumber numberWithFloat:exifLongitude] forKey:(NSString*)kCGImagePropertyGPSLongitude];
        [locDict setObject:[NSNumber numberWithFloat:location.horizontalAccuracy] forKey:(NSString*)kCGImagePropertyGPSDOP];
        [locDict setObject:[NSNumber numberWithFloat:location.altitude] forKey:(NSString*)kCGImagePropertyGPSAltitude];

        [metadata setObject:locDict forKey:(NSString*)kCGImagePropertyGPSDictionary];
    }
}
于 2013-09-17T08:14:05.647 回答
1

你可以用 Quartz 来做这件事。您可以从 UIImage 中获取 CGImage,将其与元数据结合以创建新的 CGImage。这篇文章是为了一个这样的讨论,但通过搜索 Quartz 名称和术语“元数据”应该会导致其他讨论。

于 2013-06-08T11:45:56.407 回答