我正在尝试做什么(在 10.6 下)....
我有一个图像(jpeg),其中包含图像文件中的图标(也就是说,您会看到基于文件中图像的图标,而不是程序中文件打开对话框中的通用 jpeg 图标)。我希望编辑 exif 元数据,将其保存回新文件中的图像。理想情况下,我想将其保存回文件的精确副本(即保留创建的任何自定义嵌入图标等),但是,在我手中,图标丢失了。
我的代码(为了便于阅读删除了一些位):
// set up source ref I THINK THE PROBLEM IS HERE - NOT GRABBING THE INITIAL DATA
CGImageSourceRef source = CGImageSourceCreateWithURL( (CFURLRef) URL,NULL);
// snag metadata
NSDictionary *metadata = (NSDictionary *) CGImageSourceCopyPropertiesAtIndex(source,0,NULL);
// make metadata mutable
NSMutableDictionary *metadataAsMutable = [[metadata mutableCopy] autorelease];
// grab exif
NSMutableDictionary *EXIFDictionary = [[[metadata objectForKey:(NSString *)kCGImagePropertyExifDictionary] mutableCopy] autorelease];
<< edit exif >>
// add back edited exif
[metadataAsMutable setObject:EXIFDictionary forKey:(NSString *)kCGImagePropertyExifDictionary];
// get source type
CFStringRef UTI = CGImageSourceGetType(source);
// set up write data
NSMutableData *data = [NSMutableData data];
CGImageDestinationRef destination = CGImageDestinationCreateWithData((CFMutableDataRef)data,UTI,1,NULL);
//add the image plus modified metadata PROBLEM HERE? NOT ADDING THE ICON
CGImageDestinationAddImageFromSource(destination,source,0, (CFDictionaryRef) metadataAsMutable);
// write to data
BOOL success = NO;
success = CGImageDestinationFinalize(destination);
// save data to disk
[data writeToURL:saveURL atomically:YES];
//cleanup
CFRelease(destination);
CFRelease(source);
我不知道这是否真的是图像处理、文件处理、保存后处理的问题(我可以使用 sip),或者我只是在思考(我怀疑是最后一个)。
缺口