Using MetadataExtractor in C# to get IPTC data

685 Views Asked by At

I've been struggling with how to get the various fields stored in .jpg and other image formats to store into a database with the record for the image.

I have the database stuff wired and am using MetadataExtractor to store the EXIF metadata, but IPTC is eluding me.

Has anyone nailed this?

Specifically, can you show me (with the appropriate using directives) how to get all the images into a collection so I can process each image in a foreach loop and each tag in an interior foreach loop?

I've seen several examples, but trying each causes compile errors.

What I'm doing with EXIF metadata, which works quite well, is as follows:

    public string WriteExifToFile(string DirPath, string strFileName)
    {
        string retValue = "";
        StreamWriter wrtr = new StreamWriter(DirPath);
        if (wrtr != null)
        {
            try
            {
                var directories = JpegMetadataReader.ReadMetadata(strFileName);
                foreach (var directory in directories)
                {
                    wrtr.WriteLine(directory.Name + "   " + directory.Tags.Count.ToString() + " tags.");

                    foreach (var Tag in directory.Tags)
                    {
                        wrtr.WriteLine("     " + Tag.Name);
                    }
                }
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
            }
            wrtr.Flush();
            wrtr.Close();
        }
        return retValue;
    }

However, just replacing EXIF with IPTC in the method name makes no difference. How can I make the data written to the file be the IPTC data (assuming the IPTC data is in the same structure as the EXIF data)?

0

There are 0 best solutions below