我想要做什么(在10.6下)....
What I am trying to do (under 10.6)....
我有一个图像(jpeg)您将看到基于文件中图像的图标,而不是程序中文件打开对话框中的通用jpeg图标。我想编辑exif元数据,将其保存回一个新文件中的图像。理想情况下,我想保存这个文件的精确副本(即保留任何自定义嵌入图标创建等),但是,在我手中的图标丢失。
I have an image (jpeg) that includes an icon in the image file (that is you see an icon based on the image in the file, as opposed to a generic jpeg icon in file open dialogs in a program). I wish to edit the exif metadata, save it back to the image in a new file. Ideally I would like to save this back to an exact copy of the file (i.e. preserving any custom embedded icons created etc.), however, in my hands the icon is lost.
我的代码(为了方便阅读,删除了一些位):
My code (some bits removed for ease of reading):
// 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);我不知道这是否真的是图像处理,文件处理,
I don't know if this is really a question of image handling, file handing, post-save processing (I could use sip), or me just being think (I suspect the last).
Nick
推荐答案当你发布某事,然后找到答案时,你不要讨厌。
Don't you just hate it when you post something and then find the answer....
这是使用:
// grab the original unique icon NSImage *theicon = [[NSWorkspace sharedWorkspace] iconForFile:full_file_path_of_original]]; // add it to the file after you have saved BOOL done = [[NSWorkspace sharedWorkspace] setIcon:theicon forFile:full_file_path_to_new_file options:NSExcludeQuickDrawElementsIconCreationOption];Doh!
更多推荐
使用图像(CGImage),exif数据和文件图标
发布评论