使用C#、.NET Framework 2读取IPTC信息
有没有可能用C#和.NET Framework 2读取图片的IPTC信息?
我还没有找到任何解决办法。 只有使用 .NET Framework 3.0 或 .NET 3.5 才能做到这一点。
有什么帮助,有信息吗?
来自德国的非常感谢! 斯蒂芬
is there any possibility to read the IPTC information of a picture with C# and the .NET Framework 2?
I haven't found any solution. Only with .NET Framework 3.0 oder .NET 3.5 you can do it.
Any help, any information?
Thank you very much from Germany!
Stephan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果它是在 3.x 中实现的,则它在早期版本中不存在。
然而,有一些第三方库可以做到这一点。 ImageMagick 就是其中之一。 如果您正在寻找更简单(且免费)的实现,请参阅这篇文章或谷歌搜索可能会引导您找到解决方案。
祝你好运。
If it was implemented in 3.x, it was not present in earlier versions.
However, there are 3rd party libraries that can do the trick. ImageMagick is one of them. If you are looking for a simpler (and free) implementation, this article or a google search may lead you to a solution.
Best of luck.
在尝试了这里和其他地方的一些建议但没有成功后,我决定编写一个类来调用 exiv2 命令行工具。 在我的场景中,为每个图像生成进程的小性能损失是可以接受的,但在其他场景中可能不可接受。
Having tried several suggestions from here and elsewhere with no luck, I have settled on writing a class to call out to the exiv2 command-line tool. A small performance penalty for spawning a process for each image is acceptable in my scenario, it may not be in others.
好吧,我之前的回答有点“困惑”。 以下是 .NET 2.0 项目(Visual Studio 2008 SLN 格式)的链接,该项目提供一些基本的“提取”功能 MetaExtractor ZIP (25Kb)
代码片段:
用法:
输出:
希望这比我之前的答案更有帮助。
OK, my previous answer was a little 'confused'. Here is a link to a .NET 2.0 project (Visual Studio 2008 SLN format) that provides some basic 'extraction' functionality MetaExtractor ZIP (25Kb)
CODE SNIP:
USAGE:
OUTPUT:
Hope that helps more than my previous answer.
我意识到这个答案并不涉及 .NET Framework v2,但我认为对于那些使用 .NET 3.5 或更高版本的人来说,值得记录下来。 这可能也适用于 3.0,但我还没有在那里测试过。
以下函数调用将返回嵌入在 JPEG 图像中的关键字:
BitmapDecoder 和 BitmapMetadata 类包含在通常在 WPF 中使用的程序集中,因此您需要引用以下程序集才能使用这些类:
I am在 WinForm 应用程序中成功使用了这种方法,但我怀疑它可以适用于其他应用程序类型。 此外,您还可以看到此示例中的抽象“BitmapDecoder”类被分配了一个 JpegBitmapDecoder 实例,但您可以获取适合您的图像类型的另一个解码器的实例(还支持 TIFF、GIF、PNG、BMP 和 WMP)。
I realize this answer does not address .NET framework v2, but I thought it was worth documenting for those of you who are using .NET 3.5 or higher. This might also work in 3.0 but I have not tested it there.
The following function call will return the keywords embedded in a JPEG image:
The BitmapDecoder and BitmapMetadata class are contained in an assembly that is normally used in WPF, so you'll need to reference the following assemblies to use those classes:
I am successfully using this approach in a WinForm app, but I suspect it could be adapted for other application types. Also, you can see that the abstract "BitmapDecoder" class in this example is assigned a JpegBitmapDecoder instance, but you could get an instance of another decoder for your image type (TIFF, GIF, PNG, BMP, and WMP are also supported).
Stephan,
这两个链接应该很有用
从 JPEG 读取 XMP 元数据
EXIF 提取器(在 CodeProject 上)
它们都访问 JPEG 标头的略有不同的部分以提取各种元数据可以嵌入的。 我在 Searcharoo(您可以下载) 中使用了他们的代码,并从 JPEG 中提取纬度/经度这个DeepZoom 示例。
您可以从此 13kb 代码 ZIP 获取我的
JpegParser.cs
类 - 它只获取几个属性(标题/描述/关键字/评级/纬度-经度),但您应该能够在代码中看到在哪里提取更多内容==请参阅下面的编辑==注意:上面链接的两篇文章的作者都付出了艰辛的努力。
编辑:下面的评论突出显示了我上面引用的
JpegParser.cs
包含对using System.Windows.Media.Imaging;
的引用以及BitmapImage img = new BitmapImage(new Uri(文件名));
。 这些是作为(未完成的)增强功能的一部分添加的,因此可以安全地删除它们,然后 JpegParser.cs 类应该在 2.0 中运行(尽管包含的项目不会 - 抱歉造成混乱)。或者,您可以从 JpegDocument.cs 获取类似的代码(需要进行一些编辑) Searcharoo 中的 类 - 一个索引文件(包括 JPEG)的 .NET 2.0 应用程序,例如这个搜索结果
Stephan,
These two links should be useful
Reading XMP metadata from JPEG
EXIF extractor (on CodeProject)
They both access slightly different parts of the JPEG header to extract the various metadata that can be embedded. I have used their code in Searcharoo (which you can download) and to extract the lat/long from JPEGs for this DeepZoom example.
You can grab my
JpegParser.cs
class from this 13kb code ZIP - it only grabs a couple of properties (Title/Description/Keywords/Rating/Latitude-Longitude) but you should be able to see in the code where to extract more == SEE EDIT BELOW ==NOTE: the hard work was all done by the authors of the two articles linked above.
EDIT: comment below highlight the face that the
JpegParser.cs
I referenced above includes a reference tousing System.Windows.Media.Imaging;
andBitmapImage img = new BitmapImage(new Uri(filename));
. These were added as part of an (unfinished) enhancement, so they can be safely removed and theJpegParser.cs
class should then run in 2.0 (although the containing project will not - sorry for the confusion).Alternatively, you can get similar code (some editing will be required) from JpegDocument.cs class in Searcharoo - a .NET 2.0 application that indexes files (including JPEGs) for example this search result
我刚刚搜索了几乎整个网络,寻找一个 C# 解决方案来提取 IPTC 信息,并在 Code Project 找到了这个漂亮的全新教程:
http://www.codeproject.com/KB/graphics/ReadingIPTCAPP14.aspx
希望它对某人有帮助。 :)
I have just searched almost the entire web to find a C# solution to extract IPTC information, and found this nice and brand new tutorial at Code Project:
http://www.codeproject.com/KB/graphics/ReadingIPTCAPP14.aspx
Hope it helps someone. :)