0

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

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

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

}

4

1 回答 1

1

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

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

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

于 2011-08-22T17:53:50.267 回答