oozcitak / exiflibrary

A .Net Standard library for editing Exif metadata
MIT License
131 stars 48 forks source link

Working with .tif files ? #109

Open ian-barber opened 1 year ago

ian-barber commented 1 year ago

Using this on .jpg files works but not with .tif files

file2.Properties.Set(ExifTag.Make, "12345");

rwg0 commented 1 year ago

I just encountered the same issue - the Tiff code looks as though it was never quite finished and only deals with tags that are categorized as 'IFD.Zeroth'. It won't bother writing other tags, like ones categorized as IFD.Exif.

Workaround :

var id = (ExifTag)((int)ExifTag.Make % (int)IFD.Zeroth + (int)IFD.Zeroth);
file2.Properties.Set(id, "12345");

Why does it work? The code categorizes the tag IDs by adding 100000, 200000, 300000, etc to them (the IDs are 16 bit values). The TIFF code only deals with the range from 100000 (IFD.Zeroth) to 165535. So, by remapping the tag into that range, you trick the TIFF code into writing it out. As far as I can work out, the output file is correct providing your added tags are correct.

Note that there is also some special handling of tags when they are read for Exif tags that is missed because of this issue, but the workaround may be enough.