3
我所试图做的(10.6下)....与图像(CGImage),EXIF数据和文件图标的工作
我有一个图像(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协议的问题),或者我只是在想(我怀疑是最后一个)。
尼克
对于图像,正确的解决方案是setIcon为零。 – 2012-10-09 20:09:09