2

画像の地理的位置を読み取り、ユーザーがこの情報を変更してこのデータを書き戻すことができるアプリケーションを開発しています。writeImageDataToSavedPhotosAlbum 関数を使用して、データの読み取り、操作、およびライブラリへの書き込みに成功しました。問題は、元のイメージを更新する代わりに、新しいイメージを作成することです。

そのアイテムを交換または更新するにはどうすればよいですか?

[...]

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];
}];

[...]

前もって感謝します

4

1 に答える 1

7

アプリが作成した写真のみを変更できます ( のeditableプロパティに関するドキュメントを参照してくださいALAsset)。そのためには、写真を表す を呼び出しsetImageData:metadata:completionBlock:ますALAsset

メソッドもありますwriteModifiedImageDataToSavedPhotosAlbum:metadata:completionBlock:が、元のアセットの修正版と見なされる新しいアセットが常に作成されます (その情報がどのように使用されるかは正確にはわかりません)。

于 2012-05-26T17:21:12.937 に答える