【问题标题】:Adding custom metadata tags using LibTiff.Net使用 LibTiff.Net 添加自定义元数据标签
【发布时间】:2011-08-22 17:32:29
【问题描述】:

我现在如何向图像添加自定义标签,但它没有在图像查看器中显示为标签名称。我只看到我分配的数字及其值。

为什么我的自定义标签没有合适的名称?

using BitMiracle.LibTiff.Classic;

namespace WindowsFormsApplication1
{
class Program
{
    private const TiffTag IMG_GUID = (TiffTag)666;

    private static Tiff.TiffExtendProc m_parentExtender;

    public static void TagExtender(Tiff tif)
    {
        TiffFieldInfo[] tiffFieldInfo = 
        {
            new TiffFieldInfo(IMG_GUID, -1, -1, TiffType.ASCII, FieldBit.Custom, true, false, "IMG_GUID"),
        };

        tif.MergeFieldInfo(tiffFieldInfo, tiffFieldInfo.Length);

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

    static void Main(string[] args)
    {
        // Register the extender callback
        // It's a good idea to keep track of the previous tag extender (if any) so that we can call it
        // from our extender allowing a chain of customizations to take effect.
        m_parentExtender = Tiff.SetTagExtender(TagExtender);
        byte[] buffer = new byte[25 * 144];

        string outputFileName = writeTiffWithCustomTags(buffer);

        // restore previous tag extender
        Tiff.SetTagExtender(m_parentExtender);
    }

    private static string writeTiffWithCustomTags(byte[] buffer)
    {
        string existingTiffName = "..\\..\\tifimages\\cramps.tif";
        string outputFileName = existingTiffName;
        using (Tiff image = Tiff.Open(outputFileName, "a"))
        {   
            // set custom tags
            image.SetDirectory(0);
            string value = "test";
            image.SetField(IMG_GUID, value);
            image.CheckpointDirectory();

            // Write the information to the file
            image.WriteEncodedStrip(0, buffer, 25 * 144);
        }
        return outputFileName;
    }
}

}

【问题讨论】:

  • 我尝试运行此代码,但我得到:调用 image.WriteEncodedStrip(0, buffer, 25 * 144);功能

标签: libtiff libtiff.net


【解决方案1】:

您用于查看 TIFF 的应用程序应事先了解您的自定义标签,以便能够显示其名称。

这不会发生! (因为您可以为自定义标签选择几乎任意整数)。

因此,将自定义标签显示为(整数,值)对没有任何问题。这只是自定义标签的工作方式。

【讨论】:

  • 我向您的支持台发送了一封电子邮件,其中包含了这个问题以及他们想要的更宏大的代码示例。我还附上了我正在谈论的屏幕截图。
  • 正在尝试这样做。 420c3dd1-61ee-4d8b-a659-c202816c47ae athematic
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-02
  • 2019-11-08
  • 2013-02-25
  • 1970-01-01
相关资源
最近更新 更多