使用 CGImageProperties 获取 EXIF 属性
我希望能够向 JPEG 的元数据添加文本注释,并能够从 iPhone 应用程序中读回它。
我认为这会相当简单,因为 ios4 包含对 EXIF 信息的支持。因此,我使用名为“used AnalogExif”的 Windows 工具添加了元数据,并使用以下命令从我的应用程序中读回它:
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]
这在某种程度上有效......
我在元数据字典中得到的内容类似于:
(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 似乎无法提供这些信息在我的应用程序中。
有没有人设法在 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.
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;
};
}
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.
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
many thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您认为 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. TryNSData *jpeg = [NSData dataWithContentsOfFile:@"foo.jpg"]
and you should see the EXIF.