使用C#、.NET Framework 2读取IPTC信息

发布于 2024-07-15 22:32:37 字数 165 浏览 10 评论 0原文

有没有可能用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

早茶月光 2024-07-22 22:32:38

如果它是在 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.

淤浪 2024-07-22 22:32:38

在尝试了这里和其他地方的一些建议但没有成功后,我决定编写一个类来调用 exiv2 命令行工具。 在我的场景中,为每个图像生成进程的小性能损失是可以接受的,但在其他场景中可能不可接受。

  • 使用 System.Process 调用 exiv2.exe
  • 传递参数“-pi filename.jpg”以输出所有 IPTC 字段
  • 使用 System.Process.StandardOutput.ReadToEnd() 读取输出;
  • 可以使用正则表达式将输出分成几个部分

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.

  • Call exiv2.exe using System.Process
  • Pass arguments "-pi filename.jpg" to output all IPTC fields
  • Read output using System.Process.StandardOutput.ReadToEnd();
  • The output can be split into its parts using Regex
沒落の蓅哖 2024-07-22 22:32:37

好吧,我之前的回答有点“困惑”。 以下是 .NET 2.0 项目(Visual Studio 2008 SLN 格式)的链接,该项目提供一些基本的“提取”功能 MetaExtractor ZIP (25Kb)

代码片段:

// The Parser class extracts the data to hardcoded properties.
// it's 1200 lines - too many to post on StackOverflow
JpegParser parser = new JpegParser(path);
if (parser.ParseDocument())
{
    Console.WriteLine("Parsed {0} {1}", System.IO.Path.GetFileName(path), parser.Title);
    Console.WriteLine("Tags: {0}", parser.KeywordString);
    Console.WriteLine("Description: {0}", parser.Description);
    Console.WriteLine("Title: {0}", parser.Title);
    Console.WriteLine("Rating: {0}", parser.Rating);
}

用法:

MetaExtractor "C:\Users\Craig\Pictures\anton-1.jpg"

输出:

 == DeepZoomPublisher MetaExtractor v0.1 ==
Parsed anton-1.jpg Beach Photo
Tags: beach, blue sky
Description: Anton
Title: Beach Photo
Rating: 3

Press any key to exit...

希望这比我之前的答案更有帮助。

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:

// The Parser class extracts the data to hardcoded properties.
// it's 1200 lines - too many to post on StackOverflow
JpegParser parser = new JpegParser(path);
if (parser.ParseDocument())
{
    Console.WriteLine("Parsed {0} {1}", System.IO.Path.GetFileName(path), parser.Title);
    Console.WriteLine("Tags: {0}", parser.KeywordString);
    Console.WriteLine("Description: {0}", parser.Description);
    Console.WriteLine("Title: {0}", parser.Title);
    Console.WriteLine("Rating: {0}", parser.Rating);
}

USAGE:

MetaExtractor "C:\Users\Craig\Pictures\anton-1.jpg"

OUTPUT:

 == DeepZoomPublisher MetaExtractor v0.1 ==
Parsed anton-1.jpg Beach Photo
Tags: beach, blue sky
Description: Anton
Title: Beach Photo
Rating: 3

Press any key to exit...

Hope that helps more than my previous answer.

路弥 2024-07-22 22:32:37

我意识到这个答案并不涉及 .NET Framework v2,但我认为对于那些使用 .NET 3.5 或更高版本的人来说,值得记录下来。 这可能也适用于 3.0,但我还没有在那里测试过。

以下函数调用将返回嵌入在 JPEG 图像中的关键字:

    private string[] GetKeywords(string filespec)
    {
        BitmapDecoder decoder = new JpegBitmapDecoder(new FileStream(filespec, FileMode.Open), BitmapCreateOptions.None, BitmapCacheOption.None);
        BitmapMetadata meta = (BitmapMetadata)decoder.Frames[0].Metadata;
        return meta.Keywords.ToArray<string>();
    }

BitmapDecoder 和 BitmapMetadata 类包含在通常在 WPF 中使用的程序集中,因此您需要引用以下程序集才能使用这些类:

  • PresentationCore
  • WindowsBase

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:

    private string[] GetKeywords(string filespec)
    {
        BitmapDecoder decoder = new JpegBitmapDecoder(new FileStream(filespec, FileMode.Open), BitmapCreateOptions.None, BitmapCacheOption.None);
        BitmapMetadata meta = (BitmapMetadata)decoder.Frames[0].Metadata;
        return meta.Keywords.ToArray<string>();
    }

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:

  • PresentationCore
  • WindowsBase

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).

小兔几 2024-07-22 22:32:37

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 to using System.Windows.Media.Imaging; and BitmapImage img = new BitmapImage(new Uri(filename));. These were added as part of an (unfinished) enhancement, so they can be safely removed and the JpegParser.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

漆黑的白昼 2024-07-22 22:32:37

我刚刚搜索了几乎整个网络,寻找一个 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. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文