1

I'm trying to mimic some production code to generate Tiffs with a subject for testing purposes (IE in windows, right click, go to properties and the details tab there is a subject). We place some text we need to reference later in the subject field. The field we use is 0x9c9f which as far as I can find is (Subject tag used by Windows, encoded in UCS2)

Here's the code I'm using to generate the tag

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

Basically, the tag (code wise) appears to be in the tiff but the windows properties dialog never shows it. Anything special needed to get this in place?

JasonAUnrein
  • 146
  • 6

1 Answers1

2

You are passing a bytecount, but set the passCount flag to false.

If you want to pass the count, use these lines at their correct positions:

// 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);   
Milster
  • 36
  • 1