3

I created an app which reads the JPEG meta data and stores it in the database, so that we can see if it has rogue characters. I can extract the meta data using below code but i am unable to extract copyright Status. Is there a way i can extract that?

var stream = new FileStream(file, FileMode.Open, FileAccess.Read);
                        var decoder = new JpegBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.None);
                        var metadata = decoder.Frames[0].Metadata as BitmapMetadata;
                        if (metadata != null)
                        {
                            dataGridView1.Rows.Add(file,
                                metadata.ApplicationName,
                                metadata.Author != null ? metadata.Author.Aggregate((old, val) => old ?? "" + "; " + val) : "",
                                metadata.CameraManufacturer,
                                metadata.CameraModel,
                                metadata.Comment,
                                metadata.Copyright,
                                metadata.DateTaken,
                                metadata.Format,
                                metadata.Keywords != null ? metadata.Keywords.Aggregate((old, val) => old ?? "" + "; " + val) : "",
                                metadata.Location,
                                metadata.Rating,
                                metadata.Subject,
                                metadata.Title,
                                metadata.GetQuery("/xmp/photoshop:Instructions"),
                                metadata.GetQuery("/xmp/xmpRights:UsageTerms/x-default"),
                                metadata.GetQuery("/xmp/photoshop:Credit")
                                );
                        }

Is it possible to get "Copyright status" from code? this is in Photoshop and we can view it in Photoshop.

Copyright status

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
Kamran Pervaiz
  • 1,861
  • 4
  • 22
  • 42
  • How is that different from the `Copyright` property? – Peter Ritchie Aug 19 '14 at 15:40
  • Copyright will have the ©Company but status has 3 values 'Unknown', 'Copyrighted' and 'public domain' http://www.controlledvocabulary.com/imagedatabases/is-copyright-status-important.html – Kamran Pervaiz Aug 19 '14 at 15:48
  • 1
    [This link](http://social.msdn.microsoft.com/Forums/vstudio/en-US/c034f908-969b-47c3-bb45-bd7e2282b207/unexpected-type-of-metadata-message-on-some-images-jpeg-when-adding-frame?forum=wpf) suggests perhaps: `metadata.GetQuery("/xmp/xmpRights:Marked");` (From some googling, false = public domain, true = copyrighted, null = unknown) – Bridge Aug 19 '14 at 16:11
  • thanks its giving only true or false which i think is incorrect. I think I need to compare 3 images where copyright status is different. – Kamran Pervaiz Aug 19 '14 at 16:15
  • I think you'll have to manually read the EXIF data to get at that. In which case, see http://stackoverflow.com/questions/58649/how-to-get-the-exif-data-from-a-file-using-c-sharp – Peter Ritchie Aug 19 '14 at 16:40
  • thanks bridge please post it and I will mark your answer as marked – Kamran Pervaiz Aug 21 '14 at 09:37

3 Answers3

1

There is no copyright field defined by JPEG. The Exif file format supports a copyright. Maybe others as well.

If you want the copyright information, you would have to determine if you have an Exif file. If so, you would have to look for an APP1 marker after the SOI marker, determine if it is an EXIF header, then search through the TIFF header embedded in the marker and look for a copyright tag.

user3344003
  • 20,574
  • 3
  • 26
  • 62
  • thanks and I have tried many tools to extract Exif data but could not extract copy right status, I think its a Photoshop proprietary property? – Kamran Pervaiz Aug 20 '14 at 08:48
  • There is an Adobe JPEG file format as well. THere are Adobe extension blocks. You could put some copyright text in and see where Photoshop puts it. What marker? – user3344003 Aug 20 '14 at 14:08
1

I have found the way, as Bridge suggested that Marked is the key. I asked business users for 3 images and below are my findings

metadata.GetQuery("/xmp/xmpRights:Marked")  = ""      //for unknown
metadata.GetQuery("/xmp/xmpRights:Marked")  = "false" //for public domain 
metadata.GetQuery("/xmp/xmpRights:Marked")  = "true"  //for copyrighted
Kamran Pervaiz
  • 1,861
  • 4
  • 22
  • 42
0

I had no problem getting the copyright field from a jpeg using nothing but a reference to Shell32.dll with this code that I found:

    private void ListData()
    {
        List<string> arrHeaders = new List<string>();
        List<Tuple<int, string, string>> attributes = new List<Tuple<int, string, string>>();

        Shell32.Shell shell = new Shell32.Shell();
        var strFileName = filepath;
        Shell32.Folder objFolder = shell.NameSpace(System.IO.Path.GetDirectoryName(strFileName));
        Shell32.FolderItem folderItem = objFolder.ParseName(System.IO.Path.GetFileName(strFileName));


        for (int i = 0; i < short.MaxValue; i++)
        {
            string header = objFolder.GetDetailsOf(null, i);
            if (String.IsNullOrEmpty(header))
                break;
            arrHeaders.Add(header);
        }

        // The attributes list below will contain a tuple with attribute index, name and value
        // Once you know the index of the attribute you want to get, 
        // you can get it directly without looping, like this:
        var Authors = objFolder.GetDetailsOf(folderItem, 20);

        for (int i = 0; i < arrHeaders.Count; i++)
        {
            var attrName = arrHeaders[i];
            var attrValue = objFolder.GetDetailsOf(folderItem, i);
            var attrIdx = i;

            attributes.Add(new Tuple<int, string, string>(attrIdx, attrName, attrValue));

            data.Add(string.Format("'{0}'='{1}'", attrName, attrValue));
        }
        Console.ReadLine();
    }

Found it here and altered it slightly: How to read extended file properties / file metadata

Thomas
  • 73
  • 3