我正在开发一个应用程序, 读取图像的地理位置, 让用户能够修改此信息并将此数据写回。 我成功地读取了数据, 使用写法ImageDataToSavedPhotosAlbum 函数将数据操作和写入到图书馆 。 问题在于它不是更新原始图像, 而是创建了一个新的图像 。
我如何更换或更新该项目?
[...]
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];
}];
[...]
提前感谢