Anti-Aliasing is no effect when SheetRender.toImage

Workbook workbook = new Workbook("c:/Book.xlsx");

HtmlSaveOptions options = new HtmlSaveOptions();
options.setExportActiveWorksheetOnly(true);

options.setHiddenColDisplayType(HtmlHiddenColDisplayType.HIDDEN);
options.setHiddenRowDisplayType(HtmlHiddenRowDisplayType.HIDDEN);

options.getImageOptions().setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
options.getImageOptions().setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

workbook.save("C:/Book.html", options);


SheetRender render = new SheetRender(workbook.getWorksheets().get(0), options.getImageOptions());
render.toImage(0, "C:/Book.png");

Hi,


Well, you should use EMF image format, it will give you maximum quality, you may try to change your code segment a bit to set the image format and get the resultant image in EMF file format.
e.g
Sample code:


Workbook workbook = new Workbook(“Book.xlsx”);

HtmlSaveOptions options = new HtmlSaveOptions();
options.setExportActiveWorksheetOnly(true);

options.setHiddenColDisplayType(HtmlHiddenColDisplayType.HIDDEN);
options.setHiddenRowDisplayType(HtmlHiddenRowDisplayType.HIDDEN);
options.getImageOptions().setImageFormat(ImageFormat.getEmf());
options.getImageOptions().setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
options.getImageOptions().setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

workbook.save(“f:/files/outBook1.html”, options);

SheetRender render = new SheetRender(workbook.getWorksheets().get(0), options.getImageOptions());
render.toImage(0, “f:/files/Book1.emf”);


Thank you.

I want to use PNG file format beause I need to display in web.



And the result is correct, the issue is aspose is not setRenderingHint when toImage.

I need SheetRender.toImage call setRenderingHint before generate!

When I use code:


SheetRender render = new SheetRender(workbook.getWorksheets().get(0), options.getImageOptions());

BufferedImage image = new BufferedImage(795, 1124, BufferedImage.TYPE_3BYTE_BGR);
Graphics2D g = (Graphics2D) image.getGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
render.toImage(0, g);
ImageIO.write(image, “PNG”, new File(“C:/Book2.png”));


It work fine, and anti-aliasing is work.

But this code is not graceful, I want when call toImage(int pageIndex, String fileName) and toImage(int pageIndex, OutputStream stream)

Aspose call setRenderingHint that in ImageOrPrintOptions

Hi Xiong,


Thank you for writing back.

Please execute the following piece of code against your previously shared sample spreadsheet and the latest version of Aspose.Cells for Java 8.3.2.3. Attached are the results from my end.

Java

Workbook workbook = new Workbook(“D:/temp/Book.xlsx”);

HtmlSaveOptions options = new HtmlSaveOptions();
options.setExportActiveWorksheetOnly(true);
options.setHiddenColDisplayType(HtmlHiddenColDisplayType.HIDDEN);
options.setHiddenRowDisplayType(HtmlHiddenRowDisplayType.HIDDEN);
workbook.save(“D:/SavedWithNoRenderingHints.html”, options);

options.getImageOptions().setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
options.getImageOptions().setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
workbook.save(“D:/SavedWithRenderingHints.html”, options);

ImageOrPrintOptions op = new ImageOrPrintOptions();
op.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
op.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
op.setImageFormat(ImageFormat.getPng());

SheetRender render = new SheetRender(workbook.getWorksheets().get(0), op);
render.toImage(0, “D:/SavedWithImageOrPrintOptions.png”);

SheetRender render2 = new SheetRender(workbook.getWorksheets().get(0), options.getImageOptions());
render2.toImage(0, “D:/SavedWithHtmlSaveOptions.png”);

By reviewing the results you will notice that the image quality in the HTML files generated with and without specifying the rendering hints are different. The image in the SavedWithRenderingHints.html is better in quality and smoothness, means rendering hints are working for HtmlSaveOptions.

Please also compare the results SavedWithImageOrPrintOptions.png and SavedWithHtmlSaveOptions.png, you will find the result saved using the ImageOrPrintOptions instance directly is more clear as compared to HtmlSaveOptions.getImageOrPrintOptions. However, both mentioned images do not have Rendering Hints applied so we need to investigate the matter from the perspective of SheetRender class. Please confirm your exact requirement for this scenario.

Please compare SavedWithImageOrPrintOptions.png and SavedWithRenderingHints_files\chart_Sheet1_0.png


The pie is difference. You can see pie in SavedWithImageOrPrintOptions.png is not anti-aliasing while SavedWithRenderingHints_files\chart_Sheet1_0.png is anit-aliasing

Hi again,


Thank you for writing back.

We have logged a ticket (CELLSJAVA-41208) in our issue tracking system to investigate the matter of anti aliasing not being applied while using the SheetRender to convert worksheets to image. Please check the following piece of code for reference.

Java

ImageOrPrintOptions op = new ImageOrPrintOptions();
op.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
op.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
op.setImageFormat(ImageFormat.getPng());

SheetRender render = new SheetRender(workbook.getWorksheets().get(0), op);
render.toImage(0, “D:/SavedWithImageOrPrintOptions.png”);

Please spare us little time to isolate the problem cause, and to provide the fix at earliest possible. In the meanwhile, we will keep you posted with updates in this regard.

Hi,

Thanks for using Aspose.Cells for Java.

Please download and try this fix: Aspose.Cells for Java v8.3.2.4 and let us know your feedback.

Code:
ImageOrPrintOptions op = new ImageOrPrintOptions();
op.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
op.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
op.setImageFormat(ImageFormat.getPng());
SheetRender render = new SheetRender(workbook.getWorksheets().get(0), op);
render.toImage(0, “D:/SavedWithImageOrPrintOptions.png”);

Please do not use the ImageOption in HtmlSaveOptions, in HtmlSaveOptions, the ChartImageType of ImageOption has been set to be png.

The issues you have found earlier (filed as CELLSJAVA-41208) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.