How to read the IPTC header of an image through C#?

Asked

Viewed 87 times

2

How to best read the IPTC header of an image ?

I have the following image and I needed to read her description (for a database of images), but I have already researched many ways that for me were a little confused.

Has anyone ever done this and can tell me the best way? I’m using ASP.NET MVC (C#). Follow what I want to read in the image:


inserir a descrição da imagem aqui

1 answer

2


In my view, System.Windows.Media.Imaging:

var stream = new FileStream("arquivo.jpg", FileMode.Open, FileAccess.Read);
var decoder = new JpegBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.None);
var metadata = decoder.Frames[0].Metadata as BitmapMetadata;
if(metadata != null)
    var dados = metadata.Keywords;

A more recent approach uses the Exiflib, obtaining EXIF data, which implements IPTC:

using (ExifReader reader = new ExifReader(@"arquivo.jpg"))
{
    // Os dados estão em `reader`.
}

See more here.

  • Gypsy, I tried to use this library Media.Imaging, it can not find the media, need to reference ? or download some dll?

  • It’s supposed to be on . Net’s Assembly System.Windows.

  • It does not seem to be assigning anything to Metadata, error: "Object reference not set to an instance of an object", I tried to debug everything but still it does not refer nd to Metadata.

  • I put one more example. See if it fits.

  • 1

    Gypsy, 10min before I saw your post had found the Exiflib, thanks! With this one, probably later when I improve my knowledge in the language and how everything works I will have to develop something own, but until the current state of the project, Exiflib is great.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.