Hello
When testing tiff images that are output from our system that uses Aspose.Cells I noticed that it seems that whatever compression I use only LZW is ever used which causes my tiff images not to pass the test. I am using DPF Manager (
http://www.preforma-project.eu/dpfmanager-download.html
) to test the tiff images.Our system converts many types of files into Tiff but I have only so far encountered this with Excel files/Aspose.Cells library.
My code is as follows:
private byte[] convertFromExcel(MemoryStream instream)
{
MemoryStream outstream = new MemoryStream();
Aspose.Cells.License licenceCells = new Aspose.Cells.License();
licenceCells.SetLicense(“Aspose.Total.lic”);
Workbook book = new Workbook(instream);
int counter = 1;
Bitmap bitmap = null;
ImageCodecInfo codecInfo = null;
foreach (ImageCodecInfo info in ImageCodecInfo.GetImageEncoders())
{
if (info.MimeType == “image/tiff”)
{
codecInfo = info;
break;
}
}
EncoderParameters ep = new EncoderParameters(1);
System.Drawing.Imaging.Encoder encoder = System.Drawing.Imaging.Encoder.SaveFlag;
foreach (Worksheet sheet in book.Worksheets)
{
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff;
imgOptions.HorizontalResolution = 300;
imgOptions.VerticalResolution = 300;
imgOptions.OnePagePerSheet = false;
imgOptions.TiffCompression = Aspose.Cells.Rendering.TiffCompression.CompressionNone; // Tiff compression in the file is always LZW
SheetRender sr = new SheetRender(sheet, imgOptions);
ImageCodecInfo ici = GetEncoder(ImageFormat.Tiff);
EncoderParameter parameter = new EncoderParameter(encoder, (long)EncoderValue.MultiFrame);
ep.Param[0] = parameter;
if (counter < 2)
{
bitmap = sr.ToImage(0);
if (bitmap == null)
{
throw new Exception(“Bitmap from excel sheet is null. Is the excel document empty?”);
}
bitmap.SetResolution(300F, 300F);
bitmap.Save(outstream, codecInfo, ep);
}
else
{
ep.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.FrameDimensionPage);
Bitmap bmap = sr.ToImage(0);
if (bmap != null)
{
bitmap.SaveAdd(bmap, ep);
}
}
if (counter == book.Worksheets.Count - 1)
{
ep.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.Flush);
bitmap.SaveAdd(ep);
}
counter++;
}
return outstream.ToArray();
}
Do you see anything wrong here or is there a bug in the system? We are using Aspose.Cells version 8.3.1.0