1

先生,在这里我需要将元数据中的地理位置添加到 uiimage 但添加后我只加载到相册但这里我需要那个图像,这里我添加了源代码

- (void) saveImage:(UIImage *)imageToSave withInfo:(NSDictionary *)info
{
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];


        // Get the image metadata (EXIF & TIFF)    
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    [defaults objectForKey:latkey];
    float longitude=[defaults floatForKey:longkey];
    float latitude=[defaults floatForKey:latkey];    
    CLLocation * loc=[[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
    NSMutableDictionary *metaDict = nil;
    if ([info objectForKey:UIImagePickerControllerOriginalImage] != nil) {
        metaDict = [NSMutableDictionary dictionaryWithDictionary:[info objectForKey:UIImagePickerControllerMediaMetadata]];
        NSDictionary *gpsDict = [self currentLocation:loc];
        if ([gpsDict count] > 0) {
            [metaDict setObject:gpsDict forKey:(NSString*)kCGImagePropertyGPSDictionary];
        }
    }
    [library writeImageToSavedPhotosAlbum:[imageToSave CGImage] metadata:metaDict completionBlock:^(NSURL *newURL, NSError *error) {
        if (error) {

        } else {
        }
    }];

    NSLog(@"metaDict  :%@",metaDict);


    NSURL *referenceURL = [info objectForKey:UIImagePickerControllerReferenceURL];
    [library assetForURL:referenceURL resultBlock:^(ALAsset *asset) {
        ALAssetRepresentation *rep = [asset defaultRepresentation];
        NSDictionary *metadata = rep.metadata;
        NSLog(@"%@", metadata);

        CGImageRef iref = [rep fullScreenImage] ;

        if (iref) {
            capturedImage.image = [UIImage imageWithCGImage:iref];
        }
    } failureBlock:^(NSError *error) {
            // error handling
    }];
}

为当前地理位置创建一个 EXIF 字段。

- (NSMutableDictionary*)currentLocation:(CLLocation *)location{
    NSMutableDictionary *locDict = [[NSMutableDictionary alloc] init];

    if (location != nil) {
        CLLocationDegrees exifLatitude = location.coordinate.latitude;
        CLLocationDegrees exifLongitude = location.coordinate.longitude;

        [locDict setObject:location.timestamp forKey:(NSString*)kCGImagePropertyGPSTimeStamp];

        if (exifLatitude < 0.0) {
            exifLatitude = exifLatitude*(-1);
            [locDict setObject:@"S" forKey:(NSString*)kCGImagePropertyGPSLatitudeRef];
        } else {
            [locDict setObject:@"N" forKey:(NSString*)kCGImagePropertyGPSLatitudeRef];
        }
        [locDict setObject:[NSNumber numberWithFloat:exifLatitude] forKey:(NSString*)kCGImagePropertyGPSLatitude];

        if (exifLongitude < 0.0) {
            exifLongitude=exifLongitude*(-1);
            [locDict setObject:@"W" forKey:(NSString*)kCGImagePropertyGPSLongitudeRef];
        } else {
            [locDict setObject:@"E" forKey:(NSString*)kCGImagePropertyGPSLongitudeRef];
        }
        [locDict setObject:[NSNumber numberWithFloat:exifLongitude] forKey:(NSString*) kCGImagePropertyGPSLongitude];
    }

    return [locDict autorelease];
}

请帮我

4

1 回答 1

1

编辑:您可以通过以下链接将图像添加到相册中。

现在,如果您有资产,那么使用资产的创建日期,您可以在添加到相册之前知道像这样添加的最后一张照片作为保存日期:

NSDate *imgCreateddate = [asset valueForProperty:ALAssetPropertyDate];
if(imgCreateddate isGreaterThan savedDate)
{
  last Photo;
}

请参阅将元数据添加到 iOS 图像的简单方法链接。

有关示例代码,请参阅GusUtils

请参阅保存地理标记信息与照片链接

于 2012-09-04T08:50:17.923 回答