【问题标题】:LibTiff.net isn't setting the Subject tagLibTiff.net 没有设置主题标签
【发布时间】:2015-07-28 14:08:32
【问题描述】:

我正在尝试模仿一些生产代码来生成带有主题的 Tiff 以用于测试目的(Windows 中的 IE,右键单击,转到属性和详细信息选项卡有一个主题)。我们在主题字段中放置一些稍后需要参考的文本。我们使用的字段是 0x9c9f,据我所知是(Windows 使用的主题标签,以 UCS2 编码)

这是我用来生成标签的代码

   public static void TagExtender(Tiff tif)
    {
        TiffFieldInfo[] tiffFieldInfo = 
        {
            new TiffFieldInfo(TIFFTAG_SUBJECT, 256, 256, TiffType.BYTE, FieldBit.Custom, true, false, "XPSubject"),
        };

        tif.MergeFieldInfo(tiffFieldInfo, tiffFieldInfo.Length);

        //if (m_parentExtender != null)
        //    m_parentExtender(tif);
    }


    public static void GenerateTiff(string filename, int pages = 1, bool encrypt = false, string tag = null)
    {
        // Register the custom tag handler
        if (m_parentExtender == null)
        {
            Tiff.TiffExtendProc extender = TagExtender;
            m_parentExtender = Tiff.SetTagExtender(extender);
        }

        // Open the output image 
        using (Tiff output = Tiff.Open(filename, "w"))
        {
            //...other code to generate tiff
                if (tag != null)
                {
                    byte[] bytes = UnicodeStr2HexStr(tag);
                    output.SetField(TIFFTAG_SUBJECT, bytes.Length-1, bytes); 
                }

                // Code to actually write the image ....
                output.WriteDirectory();
            }
            output.Close();
    }

基本上,标记(代码方面)似乎在 tiff 中,但 Windows 属性对话框从不显示它。需要什么特别的东西来实现这个吗?

【问题讨论】:

    标签: tags libtiff.net


    【解决方案1】:

    您正在传递一个字节数,但将 passCount 标志设置为 false。

    如果您想通过计数,请在正确的位置使用这些行:

    // Your FieldInfo
      new TiffFieldInfo((TiffTag)40095, -1, -1, TiffType.BYTE, FieldBit.Custom, true, true, "XPSubject")
    // Your Input
      byte[] test = Encoding.Unicode.GetBytes("Test3");
      tiff.SetField((TiffTag)40095, test.Length, test);   
    

    【讨论】:

      猜你喜欢
      • 2014-12-09
      • 1970-01-01
      • 2013-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-18
      • 2016-06-17
      相关资源
      最近更新 更多