disclaimer: I work for Atalasoft, which makes products for working with images through .NET.
You can do this is dotImage using the TiffDocument class with code like this:
private void RemoveIfContains(TiffTagCollection tags, int tagID)
{
TiffTag tag = tags.LookupTag(tagID);
if (tag != null)
tags.Remove(tag);
}
public void SetTiffResolution(string tiffin, string tiffout, int page, double resolution ) {
if (tiffin == tiffout)
throw new ArgumentException(tiffout, "output path must be different from input path");
TiffFile tf = new TiffFile();
using (FileStream stm = new FileStream(tiffin, FileMode.Open, FileAccess.Read, FileShare.Read)) {
tf.Read(stm);
TiffDirectory image = tf.Images[page];
RemoveIfContains(image.Tags, TiffTagID.ResolutionX);
RemoveIfContains(image.Tags, TiffTagID.ResolutionY);
RemoveIfContains(image.Tags, TiffTagID.ResolutionUnit);
image.Tags.Add(new TiffTag(TiffTagID.ResolutionX, resolution);
image.Tags.Add(new TiffTag(TiffTagID.ResolutionY, resolution);
image.Tags.Add(new TiffTag(TiffTagID.ResolutionUnit, 2)); // 2 == dots per INCH
tf.Save(tiffout);
}
}
The advantages are several - direct access to the tags lets you set things the way you want without re-encoding the image. If your initial image was compressed with JPEG inside the TIFF, you don't have to worry about issues with re-encoding JPEG data and losing information. Further, you don't have to worry about losing TIFF tag information that was already there. This code also works on multipage TIFFs. Finally, this is probably going to be a faster approach than decoding the entire image just to change a tag.
The disadvantage to this approach is that you really, really, need to understand the TIFF spec. Without that understanding, you risk creating files that may not always be parseable. DotImage and IrfanView, for example, are very lenient in consuming all manner of broken TIFFs. Adobe PhotoShop is notoriously strict.