Chart image DPI

Hello, I am trying to extract charts from workbook as image with specific DPI but it looks like following code

Workbook workbook = new Workbook("Book1.xlsx");
Chart chart = workbook.getWorksheets().get(0).getCharts().get(0);
ImageOrPrintOptions imageOrPrintOptions = new ImageOrPrintOptions();
imageOrPrintOptions.setHorizontalResolution(300);
imageOrPrintOptions.setVerticalResolution(300);
imageOrPrintOptions.setImageType(ImageType.PNG);
chart.toImage("chart.png", imageOrPrintOptions);

Generate image only with bigger size in pixels but do not set metadata so DPI or returned image is undefined.

Can I ask for adding metadata of images based on properties which are specified?

Here are result image and source workbook:
chart.png (23.7 KB)
Book1.zip (10.5 KB)

@ANDREA.FARRIS,

Thanks for the template file and image file.

Please select JPG or other relevant image format type to set your desired resolutions and then extract the image of the chart. See the updated code segment that works fine as I tested:
e.g.
Sample code:

Workbook workbook = new Workbook("Book1.xlsx");
Chart chart = workbook.getWorksheets().get(0).getCharts().get(0);
ImageOrPrintOptions imageOrPrintOptions = new ImageOrPrintOptions();
imageOrPrintOptions.setHorizontalResolution(300);
imageOrPrintOptions.setVerticalResolution(300);
imageOrPrintOptions.setImageType(ImageType.JPEG);
chart.toImage("chart.jpg", imageOrPrintOptions);

Hope, this helps a bit.

Jpeg works exactly the same for you snippet I receive following propetries:
image.png (7.5 KB)

So as you can see still 96dpi instead of requested 300dpi

I use version 22.5 of aspose-cells

@ANDREA.FARRIS,

Aspose.Cells renders images in 96dpi or you may use some vector image type, e.g., EMF to get quality output image for the chart.

@ANDREA.FARRIS

We have some adpatations for setting JPG image with sepcific DPI.
Could you please share us som infos about your environment?

  1. OS version
  2. JDK/OpenJDK version.

So setting “Resolution” is only considered in image size and there is no build-in way to retrieve image with proper/requested metadata.

About my env: Windows 10 22H2 and Eclipse Adoptium JDK 17.0.4.101

@ANDREA.FARRIS,

Thanks for the environment details.

To evaluate and support your requirements, we have now logged the following two (enhancement) tickets:

  • CELLSJAVA-44936 - Set chart image (PNG) DPI settings
  • CELLSJAVA-44937 - Set chart image (JPG) DPI settings

We will look into the details of the issues and figure out soon.

Once we have an update on any of the tickets, we will update you.

@ANDREA.FARRIS,

This is to inform you that your issues have been resolved now. The fix will be included in our upcoming release (Aspose.Cells v22.12) which is scheduled in the first half of December, 2022. You will also be notified when the next version is released.

The issues you have found earlier (filed as CELLSJAVA-44936,CELLSJAVA-44937) have been fixed in this update. This message was posted using Bugs notification tool by Peyton.Xu