Reading IPTC Information Using C #, .NET Framework 2

is it possible to read IPTC information about the picture from C # and the .NET Framework 2?

I did not find any solution. Only with .NET Framework 3.0 or .NET 3.5 can you do this.

Any help, any information?

Thanks a lot from Germany! Stephan

+4
source share
6 answers

OK, my previous answer was a bit puzzled. Here is a link to a .NET 2.0 project (Visual Studio 2008 SLN format) that provides some basic MetaExtractor ZIP “extract” functions (25Kb)

CODE SNIP:

// The Parser class extracts the data to hardcoded properties. // it 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); } 

APPLICATION:

 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 this helps more than my previous answer.

+3
source

I understand that this answer does not apply to the .NET framework v2, but I thought it was worth documenting for those of you who are using .NET 3.5 or higher. This may also work in version 3.0, but I did not test it there.

The following function call will return keywords embedded in the 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 classes are contained in the assembly that is commonly used in WPF, so you will need to reference the following assemblies to use these classes:

  • PresentationCore
  • WindowsBase

I have successfully used this approach in a WinForm application, but I suspect that it may be adapted for other types of applications. In addition, you can see that the abstract class "BitmapDecoder" in this example is assigned an instance of JpegBitmapDecoder, but you can get an instance of another decoder for your image type (TIFF, GIF, PNG, BMP and WMP are also supported).

+2
source

Stephan

These two links should be helpful.

Reading XMP metadata from JPEG

EXIF Extractor (in CodeProject)

They access several parts of the JPEG header to extract various metadata that can be embedded. I used my code in Searcharoo (which you can download) and extract the lat / long from JPEG for this DeepZoom example .

You can grab my JpegParser.cs class from 13kb ZIP code - it only grabs a few properties (Title / Description / Keywords / Rating / Latitude-Longitude), but you should be able to see in the code where you can extract more. == SEE CHANGE BELOW ==

NOTE: the hard work was done by the authors of the two articles cited above.

EDIT: the comment below shows the person referenced by JpegParser.cs , a link to using System.Windows.Media.Imaging; and BitmapImage img = new BitmapImage(new Uri(filename)); . They were added as part of an (incomplete) improvement, so they can be safely removed, and the JpegParser.cs class should work in version 2.0 (although the project will not be there - sorry for the confusion).

Alternatively, you can get the same code (some editing will be needed) from the JpegDocument.cs class in Searcharoo - a .NET 2.0 application that indexes files (including JPEG), for example, a search result

+1
source

I just searched almost the entire network to find a C # solution for extracting IPTC information, and found this beautiful and brand new tutorial in Code Project:

http://www.codeproject.com/KB/graphics/ReadingIPTCAPP14.aspx

Hope this helps someone. :)

+1
source

If it was implemented in 3.x, it was not present in earlier versions.

However, there are third-party libraries that can do the trick. ImageMagick is one of them. If you're looking for a simpler (and free) implementation, this article or Google search may lead you to a solution.

Good luck.

0
source

Having tried some tips from here and elsewhere, no luck, I decided to write a class to call the exiv2 command-line tool. In my scenario, a slight decrease in performance is acceptable for spawning a process for each image, perhaps this does not apply to others.

  • Call exiv2.exe using System.Process
  • Skip arguments "-pi filename.jpg" to display all IPTC fields
  • Reading output using System.Process.StandardOutput.ReadToEnd ();
  • The output can be broken into pieces using Regex
0
source

All Articles