如何在C#中从JPEG中提取“版权状态”

时间:2014-08-19 15:38:43

标签: c# metadata jpeg photoshop xmp

我创建了一个应用程序,它读取JPEG元数据并将其存储在数据库中,以便我们可以看到它是否有流氓字符。我可以使用下面的代码提取元数据,但我无法提取版权状态。有没有办法可以提取出来?

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")
                                );
                        }

是否有可能获得"版权状态"从代码?这是在Photoshop中,我们可以在Photoshop中查看它。

Copyright status

3 个答案:

答案 0 :(得分:1)

JPEG没有定义版权字段。 Exif文件格式支持版权。也许其他人也是。

如果您需要版权信息,则必须确定是否有Exif文件。如果是这样,您必须在SOI标记后面查找APP1标记,确定它是否是EXIF标题,然后搜索标记中嵌入的TIFF标题并查找版权标记。

答案 1 :(得分:1)

我找到了方法,因为Bridge建议Marked是关键。我向商业用户询问了3张图片,以下是我的调查结果

metadata.GetQuery("/xmp/xmpRights:Marked")  = ""      //for unknown
metadata.GetQuery("/xmp/xmpRights:Marked")  = "false" //for public domain 
metadata.GetQuery("/xmp/xmpRights:Marked")  = "true"  //for copyrighted

答案 2 :(得分:0)

除了使用我发现的以下代码对Shell32.dll的引用外,我从jpeg获取版权字段没有问题:

    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();
    }

在这里找到它并稍作改动: How to read extended file properties / file metadata