English 中文(简体)
替换 iOS ALA AssetsLibrary 中的 ALAsset 对象
原标题:Replace ALAsset object in iOS ALAssetsLibrary

我正在开发一个应用程序, 读取图像的地理位置, 让用户能够修改此信息并将此数据写回。 我成功地读取了数据, 使用写法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];
}];

[...]

提前感谢

最佳回答

您只能更改您应用程序创建的照片( 见 ediable 属性 ALAssset 上的文件) 。 为此, 请在代表照片的 setImaageData:metadata:\block: 上调 ALAsssset

s 还有一个 write ModifedImaageDataToSavedPhotosAlbum:metadata: completeBlock: 方法,但它总是创建一个新资产,被视为原始资产的修改版本(我不清楚该信息是如何使用的)。

问题回答

暂无回答




相关问题
How to change out-of-focus text selection color in Xcode?

Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...

Iphone NSTimer Issue

Hi I am new to objective c. I am trying to make an app for iphone. I have a button on my view, and the click on which the function playSound is called. This is working properly. It does plays the ...

Include a .txt file in a .h in C++?

I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....

Iterating over string/strlen with umlauted characters

This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...

Xcode open two editor windows with same file

Is it possible to open the same file in two separate windows in Xcode. I can open a file in one window and the same file in the main Xcode editor window, but I wanted two separate fulltime editor ...

Forcing code signing refresh in Xcode

In our environment, we share resources across multiple projects and platforms. When building for iPhone, only a subset of those resources are needed. Since that subset is still considerable, we have ...

热门标签