Building a tiff header in libtiff.net

869 Views Asked by At

I am reading a CG4 (CALS Group IV bitmap) file and extracted the image data as an array of bytes. The image data is compressed using CCITT Group 4 (T.6) compression.

I don't believe libtiff.net has methods to just un-compress a set of compressed bytes. Is there a way to build a tiff header specifying CCITT Group 4 compression, and then slot in my existing compressed image data, to produce a valid tiff file?

1

There are 1 best solutions below

2
On BEST ANSWER

Here is a sample that shows how to create black-and-white TIFF from your bytes

using (Tiff output = Tiff.Open(fileName, "w"))
{
    output.SetField(TiffTag.IMAGEWIDTH, width);
    output.SetField(TiffTag.IMAGELENGTH, height);
    output.SetField(TiffTag.SAMPLESPERPIXEL, 1);
    output.SetField(TiffTag.BITSPERSAMPLE, 8);
    output.SetField(TiffTag.ORIENTATION, Orientation.TOPLEFT);
    output.SetField(TiffTag.ROWSPERSTRIP, height);
    output.SetField(TiffTag.XRESOLUTION, 88.0);
    output.SetField(TiffTag.YRESOLUTION, 88.0);
    output.SetField(TiffTag.RESOLUTIONUNIT, ResUnit.INCH);
    output.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG);
    output.SetField(TiffTag.PHOTOMETRIC, Photometric.MINISBLACK);
    output.SetField(TiffTag.COMPRESSION, Compression.CCITTFAX4);
    output.SetField(TiffTag.FILLORDER, FillOrder.MSB2LSB);

    output.WriteRawStrip(0, compressedData, compressedData.Length);
}

Please note that you must provide correct width, height, resolution and other values. And ROWSPERSTRIP must be correct too.