Hi Ikram,
Thanks for the quick reply. :)
I've acctually been looking at the example you are linking to, but no dice. :|
I can't send you the files 'cus it's confidential data :o) My code looks like this as you'll notice it's build from examples on this site :) :
private static void FixTiffFile(string sourceFilePath)
{
try
{
FileInfo fi = new FileInfo(sourceFilePath);
string fileName = fi.Name;
// By default the cache folder is set to the local temp directory.
// You can specify a different cache folder from the default this way:
Cache.CacheFolder = @"Temp";
// Auto mode is flexible and efficient
Cache.CacheType = CacheType.Auto;
// The default cache max value is 0, which means that there is no upper limit
Cache.MaxDiskSpaceForCache = 0;
Cache.MaxMemoryForCache = 1073741824; // 1 gigabyte
// We do not recommend that you change the following property because it may greatly affect performance
Cache.ExactReallocateOnly = false;
//Load input Tiff image
using (TiffImage source = (TiffImage)Aspose.Imaging.Image.Load(sourceFilePath))
{
//Create an instance of TiffOptions for resultant Tiff image
TiffOptions options = new TiffOptions(TiffExpectedFormat.TiffJpegYCBCR);
options.Source = new FileCreateSource(string.Format(@"FixedTifFiles\{0}", fileName), false);
using (TiffImage result = (TiffImage)Aspose.Imaging.Image.Create(options, source.Width, source.Height))
{
foreach (TiffFrame frame in source.Frames)
{
//Create a copy of the frame for further processing
TiffFrame copiedFrame = TiffFrame.CopyFrame(frame);
var compressionType = copiedFrame.FrameOptions.Compression;
switch (compressionType)
{
case TiffCompressions.Jbig:
copiedFrame.FrameOptions.Compression = TiffCompressions.Jpeg;
copiedFrame.FrameOptions.BitsPerSample = new ushort[] { 8, 8, 8 };
copiedFrame.FrameOptions.Photometric = TiffPhotometrics.Ycbcr;
break;
case TiffCompressions.Jp2000:
copiedFrame.FrameOptions.Compression = TiffCompressions.Jpeg;
copiedFrame.FrameOptions.BitsPerSample = new ushort[] { 8, 8, 8 };
copiedFrame.FrameOptions.Photometric = TiffPhotometrics.Ycbcr;
break;
case TiffCompressions.Jpeg:
copiedFrame.FrameOptions.Compression = TiffCompressions.Jpeg;
copiedFrame.FrameOptions.BitsPerSample = new ushort[] { 8, 8, 8 };
copiedFrame.FrameOptions.Photometric = TiffPhotometrics.Ycbcr;
break;
case TiffCompressions.Lzw:
copiedFrame.FrameOptions.Compression = TiffCompressions.Lzw;
copiedFrame.FrameOptions.BitsPerSample = new ushort[] { 8 };
copiedFrame.FrameOptions.Photometric = TiffPhotometrics.Rgb;
copiedFrame.FrameOptions.Predictor = TiffPredictor.Horizontal;
break;
case TiffCompressions.Ojpeg:
copiedFrame.FrameOptions.Compression = TiffCompressions.Jpeg;
copiedFrame.FrameOptions.BitsPerSample = new ushort[] { 8, 8, 8 };
copiedFrame.FrameOptions.Photometric = TiffPhotometrics.Ycbcr;
break;
default:
break;
}
//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();
}
}
}
catch (Exception ex)
{
Console.WriteLine("FixTiffFile: " + ex.Message);
Console.WriteLine("FixTiffFile: " + ex.StackTrace);
Console.ReadKey();
}
}