Image gets blurred when added to Excel through JXL
I use the JXL API to add an Image to an Excel file. Libraries used:
jcommon (1.0.14) jfreechart (1.0.13) jxl (2.6.10)// chartImage is of type BufferedImage
com.KeyPoint.PngEncoder encoder = new com.KeyPoint.PngEncod开发者_Python百科er(chartImage, true, 0, 0);
jxl.write.WritableImage image = new jxl.write.WritableImage(0, 2, (chartImage.getWidth()/100),16,
encoder.pngEncode());
sheet.addImage(image);
The problem is that the WritableImage constructors take widths and heights in terms of rows and columns (width: column 0 to column chartImage.getWidth()/100, height: row 2 to row 16). This causes the chart image to blur.
How do I get the original image into the Excel using JXL? Kindly help. Thanks! :-)The issue lies with either the compression used in Excel or the encoder you used.
A solution that works is drawing the chart larger than the intended image, and then letting Excel do the down-scaling. This ensures clarity although a chart-filled workbook will be much larger than before.
AFAIK that is the only solution to the problem. I have had similar issues with Word and PowerPoint, and the solution seems to be upscaling.
When you scale the chart you should note that the font sizes need to be changed too.
Don't use PngEncoder
directly. Instead, use the relevant ChartUtilities
method, which will find the Sun/Oracle PNG encoder if available.
精彩评论