使用图像(CGImage),exif数据和文件图标

编程入门 行业动态 更新时间:2024-10-27 23:28:36
本文介绍了使用图像(CGImage),exif数据和文件图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想要做什么(在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数据和文件图标

本文发布于:2023-07-30 16:22:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1251011.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图标   图像   文件   数据   exif

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!