0

I am trying to just change the resolution of a tiff image using Bit Miracle libtiff. Below is the code snippet. When I do this, tiff image resolution is changed, but the other tiff parameters are gone and I am unable to open the tiff file. Could you please help if I am doing something wrong here?

using (Tiff image = Tiff.Open(fileName, "a"))
{
 image.SetField(TiffTag.XRESOLUTION, 200);
 image.SetField(TiffTag.YRESOLUTION, 300);
 image.WriteDirectory();
}
ktpg
  • 1

1 Answers1

2

Please note that changing TiffTag.XRESOLUTION or TiffTag.YRESOLUTION won't change image data and will only change the way the data is interpreted by viewers or printers.

As for the code itself, you should:

  • Call SetDirectory(0) before calling SetField methods. That's because you open file in append mode.

  • Use RewriteDirectory instead of WriteDirectory. Otherwise you might corrupt image data.

Bobrovsky
  • 13,789
  • 19
  • 80
  • 130