Chart to JPEG image gives black background

Hi,


I am using chart.toImage(…) API to transform an excel chart to jpeg image.
I get the image but with black background though the source chart is with transparent background.

Attached a sample excel file with the incorrect image output.
Could you please verify this issue.

Aspose cells version being used: aspose-cells-8.3.2.jar.


Thanks,
Jaspreet





Hi Jaspreet,


Thanks for the template file and some details.

Well, I am afraid, JPG format does not support transparency (see the thread for your reference: http://stackoverflow.com/questions/9147883/only-png-supports-transparency-is-that-true), so you are getting black chart area in the chart image. Please use PNG, EMF or any other suitable image file format for your needs. I have tested using PNG, EMF file formats, it works fine and does not render the chart image with black background color.

Thank you.

Hi,

In context of this issue I have another sample wherein the JPEG output is fine (white background & not black).
Check the attached excel document & JPEG output of Chart 1 in Rev Model sheet.


–Jaspreet


Hi Jaspreet,


In order to understand this scenario, please check the properties of the Chart Area of two aforementioned charts in Excel application. You will notice that the Fill property of the chart in Sample Excel.xlsx is set to No fill, that means; the Chart Area is transparent. Now, repeat the same for the chart in the spreadsheet Innovation_030414 (2).xlsx. You will see that the Fill property is set to Automatic, that actually means white. When you render both charts to Jpeg format, the transparent area will be rendered black because Jpeg format does not support transparency (alpha channel) whereas in second case the white area will be rendered white.

In order to deal with transparency, you have to choose the format that could support it, such as PNG from raster image formats. Please check the attachment for the PNG & Jpeg images generated for both charts.