Change Compression of TIFF file

Hello!

I have some TIFF images that are compressed with LZW, but an older application we have doesn’t like LZW. Can I use Aspose.PDF to convert a TIFF to a different compression format?

Thanks!

Doug

Hi Doug,

Thanks for contacting support.

Aspose.Pdf for .NET provides the feature to create as well as manipulate existing PDF files. As per your requirement, you may consider first converting TIFF image to PDF format and then convert PDF pages to TIFF image with desired compression. For more information, please visit

Besides this, we have an API named Aspose.Imaging which provides the support to deal with various image formats. I am moving this thread to respective forum where my fellow worker from respective team will further share his feedback.

Hi Doug,


Thank you for using Aspose products.

I would like to address your concerns from Aspose.Imaging’ perspective. As discussed by my colleague, Aspose.Imaging APIs deal with all image formats, and they also provide means to change the compression of a Tiff image. The supported compression types at the moment are None, LZW, CcittRle & CcittFax4. If you wish to change the compression of any existing Tiff image to aforesaid compression types, you may consider using the following piece of code for the purpose.

C#

//Load input Tiff image
TiffImage source = (TiffImage)Image.Load(myDir + “sample.tif”);
//Create an instance of TiffOptions for resultant Tiff image
TiffOptions options = new TiffOptions();
//Set the source for resultant Tiff image
//Last Boolean parameter denotes to IsTemporal
options.Source = new FileCreateSource(myDir + “result.tif”, false);
//Create a new Tiff image while passing the instance of TiffOptions & expected image dimensions
//If the source image has multiple frames, each frame would have its own dimensions
//irrespective of size provided at the time of image creation
using (TiffImage result = (TiffImage)Image.Create(options, source.Width, source.Height))
{
//Tiff image may contain more than one frame
//Iterate over the collection of input image frames
foreach (TiffFrame frame in source.Frames)
{
//Create a copy of the frame for further processing
TiffFrame copiedFrame = TiffFrame.CopyFrame(frame);
//In a multi-page Tiff image, we can set the different compression for each frame
copiedFrame.FrameOptions.Compression = TiffCompressions.CcittFax3;
//Set the BitsPerSample for the frame: The value depends on the compression type selected
copiedFrame.FrameOptions.BitsPerSample = new ushort[] { 1 };
//Set the Photometric for the frame: The value depends on the compression type selected
copiedFrame.FrameOptions.Photometric = TiffPhotometrics.MinIsBlack;
//Add copied frame to the destination image
result.AddFrame(copiedFrame);
}
//The first frame is created by default, we may just remove it as it is empty
//But it is not possible to remove the empty frame unless there are more than one frames
if (result.Frames.Length > 1)
{
//Set next frame as Active
result.ActiveFrame = result.Frames[1];
//Remove the first frame
result.RemoveFrame(0);
}
// Save the image with changes
result.Save();
}

Please feel free to write back in case you need our further assistance.