2012-05-26 52 views
2

我正在开发一个应用程序,该应用程序读取图像的地理位置并允许用户修改此信息并将此数据写回。我使用writeImageDataToSavedPhotosAlbum函数成功读取数据,操作和写入库。问题是,改为更新原始图像,它创建一个新的。替换iOS中的ALAsset对象ALAssetsLibrary

我该如何更换或更新该项目?

[...] 

NSMutableDictionary *EXIFDictionary = [[[metadata objectForKey:(NSString *)kCGImagePropertyExifDictionary]mutableCopy]autorelease]; 
NSMutableDictionary *GPSDictionary = [[[metadata objectForKey:(NSString *)kCGImagePropertyGPSDictionary]mutableCopy]autorelease]; 
NSMutableDictionary *TIFFDictionray = [[[metadata objectForKey:(NSString *)kCGImagePropertyTIFFDictionary]mutableCopy]autorelease]; 

Byte *buffer = (Byte*)malloc(representation.size); 
NSUInteger buffered = [representation getBytes:buffer fromOffset:0.0 length:representation.size error:nil]; 
NSData *imageData = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES]; //this is NSData may be what you want 

if(!EXIFDictionary) { 
    //if the image does not have an EXIF dictionary (not all images do), then create one for us to use 
    EXIFDictionary = [NSMutableDictionary dictionary]; 
} 
if(!GPSDictionary) { 
    GPSDictionary = [NSMutableDictionary dictionary]; 
} 
if(!TIFFDictionray) { 
    TIFFDictionray = [NSMutableDictionary dictionary]; 
} 


[TIFFDictionray setObject:@"This should be the image description" forKey:(NSString*)kCGImagePropertyTIFFImageDescription]; 
[EXIFDictionary setObject:@"This should be the user comment" forKey:(NSString*)kCGImagePropertyExifUserComment]; 

[metadataAsMutable setObject:TIFFDictionray forKey:(NSString*)kCGImagePropertyTIFFDictionary]; 
[metadataAsMutable setObject:EXIFDictionary forKey:(NSString*)kCGImagePropertyExifDictionary]; 

__block NSDate *date = [[NSDate date] retain]; 

ALAssetsLibrary *library = [[ALAssetsLibrary alloc]init]; 

[library writeImageDataToSavedPhotosAlbum:imageData metadata:metadataAsMutable completionBlock:^(NSURL *assetURL, NSError *error) { 
    NSLog(@"Saving Time: %g", [[NSDate date] timeIntervalSinceDate:date]); 
    [date release]; 
}]; 

[...] 

在此先感谢

回答

7

你只能改变你的应用程序创造的照片(见的ALAsseteditable属性的文档)。为此,请在代表照片的ALAsset上致电setImageData:metadata:completionBlock:

还有一个writeModifiedImageDataToSavedPhotosAlbum:metadata:completionBlock:方法,但它总是创建一个新的资产,被认为是原始资产的修改版本(我不确定如何使用这些信息)。

+0

因此,假设我使用我的应用程序获取照片,关闭应用程序,并且在我希望修改元数据后的第二天,那么可能呢?还是只是在运行时,当我得到的图片,然后我把它保存到图书馆? –

+0

这应该是可以的,是的。 – omz

+0

“元数据:”字典参数的格式记录在哪里?我似乎无法正确设置它。 –