我已设法通过以下步骤将GPS坐标添加到元数据中:
writeImageToSavedPhotosAlbum
)ALAsset
从磁盘中读取并将其转换为jpeg NSData
如果没有保存/读取到磁盘的麻烦,我可以这样做吗?
答案 0 :(得分:1)
你可以使用Quartz做一些困难。您可以从UIImage获取CGImage,将其与元数据结合以创建新的CGImage。 This post进行一次此类讨论,但通过搜索Quartz名称和术语"元数据"应该导致其他人。
答案 1 :(得分: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];
}
}