Conversion xls or xlsx to tiff ImageSaveOptions ConversionDepths

Hello Aspose Team


Im converting the xls and xlsx to tiff right now and it works, but i need to set the ConversionDepths to Depth1bpp i don’t know how to set this parameter actually i am setting the parameter compression like this


Aspose.Cells.Rendering.ImageOrPrintOptions.ImageOrPrintOptions imgOptions = new Aspose.Cells.Rendering.ImageOrPrintOptions.ImageOrPrintOptions();

imgOptions.TiffCompression = Aspose.Cells.Rendering.TiffCompression.CompressionCCITT4;


on the ppt file i use this

Aspose.Slides.Export.TiffOptions option = new Aspose.Slides.Export.TiffOptions();
opts.PixelFormat = Aspose.Slides.Export.ImagePixelFormat.Format1bppIndexed;

but i don’t know how to do it with the excel files

Hi,

Thanks for your posting and using Aspose.Cells.

We have looked into your issue with the latest version:
Aspose.Cells for .NET (Latest Version) and found that it supports your requirements.

Please use the ImageOrPrintOptions.PixelFormat property for your needs.

C#

imgOptions.TiffCompression = Aspose.Cells.Rendering.TiffCompression.CompressionCCITT4;
imgOptions.PixelFormat = PixelFormat.Format1bppIndexed;

when i try to set this on the save i have this exception:


"A Graphics object cannot be created from an image that has an indexed pixel format."

and the image generated says on the viewer is empty

Hi,

Thanks for your feedback and using Aspose.Cells.

We have tested this issue with the following sample code using the latest version:
Aspose.Cells for .NET v8.8.0.2 with the sample excel file attached with this post and found it throws exception as you have mentioned.

We have logged this issue in our database for investigation. We will look into it and fix this issue. Once the issue is resolved or we have some other update for you, we will let you know asap.

This issue has been logged as

  • CELLSNET-44418 - Save to Tiff - Using PixelFormat.Format1bppIndexed throws exception

I have also shown the exception generated by the code for a reference.

C#
Workbook wb = new Workbook(“source.xlsx”);

Worksheet ws = wb.Worksheets[0];

ImageOrPrintOptions opts = new ImageOrPrintOptions();
opts.SaveFormat = SaveFormat.TIFF;
opts.TiffCompression = TiffCompression.CompressionCCITT4;
opts.OnePagePerSheet = true;
opts.PixelFormat = PixelFormat.Format1bppIndexed;

SheetRender sr = new SheetRender(ws, opts);
sr.ToImage(0, “Test.tiff”);

Exception
Aspose.Cells.CellsException was unhandled
HResult=-2146232832
Message=A Graphics object cannot be created from an image that has an indexed pixel format.
Source=Aspose.Cells
StackTrace:
at . (Int32 , ImageOrPrintOptions )
at . (Int32 , ImageOrPrintOptions , Stream )
at . (Int32 , ImageOrPrintOptions , Stream )
at . (Int32 , String , ImageOrPrintOptions )
at Aspose.Cells.Rendering.SheetRender.ToImage(Int32 pageIndex, String fileName)
at CellsNET.Program.f1() in d:\Aspose\Projects\NET\AsposeProject\CellsNET\Program.cs:line 59
at CellsNET.Program.Main(String[] args) in d:\Aspose\Projects\NET\AsposeProject\CellsNET\Program.cs:line 30
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:

Hi,


We have evaluated your issue “CELLSNET-44418” further. For your information, when you set TiffCompression.CompressionCCITT4 or TiffCompression.CompressionCCITT3, the generated tif image is already as 1bpp depth image, so kindly do not use the following line of code or comment out the following line of code to render the tiff image:
e.g
Sample code:

opts.PixelFormat = PixelFormat.Format1bppIndexed;

I have generated the output TIFF image after commenting out the above line of code. Kindly check the relevant attribute for the output tiff image’s detail info, see the screenshot for your reference:
http://prntscr.com/b0igwa

Thank you.