问题描述
我希望能够在JPEG的元数据中添加文本注释,并能够从iphone应用程序中读回它.
I want to be able to add a text comment to the metadata of a JPEG and be able to read it back from within an iphone app.
我认为这很简单,因为ios4包含对EXIF信息的支持.因此,我使用一个名为usedAnalogExif的Windows工具添加了元数据,并使用以下命令从我的应用中读取了该数据:
I thought this would be fairly simple as ios4 contains support for EXIF info. So I added metadata using a Windows tool called used AnalogExif and read it back from my app using:
NSData *jpeg = UIImageJPEGRepresentation(myUIImage,1.0);
CGImageSourceRef source = CGImageSourceCreateWithData((CFDataRef)jpeg, NULL);
NSDictionary *metadata = (NSDictionary *) CGImageSourceCopyPropertiesAtIndex(source,0,NULL);
NSMutableDictionary *metadataAsMutable = [[metadata mutableCopy]autorelease];
[metadata release];
NSMutableDictionary *EXIFDictionary = [[[metadataAsMutable objectForKey:(NSString *)kCGImagePropertyExifDictionary]
那行得通...到一个点:)
And that works...to a point :)
我在元数据字典中得到的内容类似于:
What I get back in the metadata dictionary is something like:
(gdb) po metadata
{
ColorModel = RGB;
Depth = 8;
Orientation = 1;
PixelHeight = 390;
PixelWidth = 380;
"{Exif}" = {
ColorSpace = 1;
PixelXDimension = 380;
PixelYDimension = 390;
};
"{JFIF}" = {
DensityUnit = 0;
JFIFVersion = (
1,
1
);
XDensity = 1;
YDensity = 1;
};
"{TIFF}" = {
Orientation = 1;
};
}
但这就是我所能得到的!我已经使用可以找到的每个EXIF编辑器(大多数情况下应该是PC的)来编辑JPEG文件,尽管他们都说我已经添加了JPEG注释,EXIF标题和关键字,但是这些信息似乎都无法从Apple SDK中获得.在我的应用中.
But thats all I can get! I've edited the JPEG file with every EXIF editor I can find (mostly PC ones I should say) and although they all say I have added JPEG comments and EXIF captions and keywords, none of that info seems to be available from the Apple SDK in my app.
是否有人设法在jpeg的元数据中设置一个文本字段,并设法从iPhone应用程序中读取该文本字段?
Has anyone managed to set a text field in the metadata of a jpeg and manage to read it back from an iphone app?
我根本不想使用第三方库
I didn't want to use a third party library if at all possible
非常感谢
推荐答案
您认为iOS确实比您所看到的支持更多的元数据是正确的.创建UIImage
并将其转换回JPEG时,可能会丢失数据.尝试NSData *jpeg = [NSData dataWithContentsOfFile:@"foo.jpg"]
,您应该会看到EXIF.
You're correct in thinking that iOS does support more metadata than what you're seeing. You probably lost the data when you created a UIImage
and then converted it back to JPEG. Try NSData *jpeg = [NSData dataWithContentsOfFile:@"foo.jpg"]
and you should see the EXIF.
这篇关于使用CGImageProperties获得EXIF属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!