7

I have a file with the following properties:

Coral image properties

I want to get the description title "Dragon's Eye Coral". How would I go about doing this?

I have been trying to do it with the following code but without any result:

public string GetImageTitle(Image img)
    {
        const int metTitle = 0x0320;
        var props = img.PropertyItems;
        var Title = props.FirstOrDefault(x => x.Id == metTitle);
        if (Title != null)
        {
            var myObject = Encoding.ASCII;
            var PicTitle = myObject.GetString(Title.Value, 0, Title.Len - 1);
            return PicTitle;
        }
        return "";
    }

1 Answers1

2

I have tried the below code and its working fine.. u just need to change the metTitle int value

        Image im = Image.FromFile("image file path");
        System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();            
        var allPoprItem = im.PropertyItems;
        const int metTitle = 0x10e;
        var Title = allPoprItem.FirstOrDefault(x => x.Id == metTitle);
        Console.WriteLine(encoding.GetString(Title.Value));

I am able to get the whatever title i set to an image.. try this..

Deepak Sharma
  • 4,124
  • 1
  • 14
  • 31
  • Thanks, i appreachiate it but that didn't work sadly. Even if i loop through every PropertyItem i can't find the title. – Andreas Ljungström Jan 28 '14 at 20:34
  • Actually ... It must have been a corrupt image file I've been working with. Created a new file and set the title property on that instead and i get read that without problem... Makes me sad I spent so much time on this when it all was a corrupt file :/ – Andreas Ljungström Jan 28 '14 at 20:56
  • @AndreasLjungström no issue.. it happens sometime.. bt atleaset we learnt something.. :) – Deepak Sharma Jan 29 '14 at 04:02
  • 1
    You should use `Encoding.UTF7.GetString(Title.Value)`. That works for German Umlauts. – Marcel Dec 30 '16 at 15:00