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];
}];
[...]
在此先感謝
因此,假設我使用我的應用程序獲取照片,關閉應用程序,並且在我希望修改元數據後的第二天,那麼可能呢?還是隻是在運行時,當我得到的圖片,然後我把它保存到圖書館? –
這應該是可以的,是的。 – omz
「元數據:」字典參數的格式記錄在哪裏?我似乎無法正確設置它。 –