How to change the quality of generated pictures

public static void main(String[] args) {
Presentation pres = new Presentation(“aaa.pdf”);
try {
// Render presentation to images array slide by slide
for (int i = 0 ; i < pres.getSlides().size(); i++)
{
// Control hidden slides (do not render hidden slides)
if (pres.getSlides().get_Item(i).getHidden())
continue;
BufferedImage bmp = pres.getSlides().get_Item(i).getThumbnail(2f, 2f);
// Create file name for an image
String outputFilePath = “aaa.jpg”;

            final Instant now = Instant.now();
            File file = new File(outputFilePath);
            ImageIO.write(bmp, "jpg",file);
        }
    } catch (Exception e) {
        log.warn(e+"");
        throw new RuntimeException(e);
    }
}

@zyx,
Thank you for the query. Unfortunately, Aspose.Slides still cannot load PDF files. I checked the image quality using conversion the same way for a presentation (PPTX -> Bitmap -> JPG) and found it perfect.

If you found an issue, please share and specify the following:

  • input presentation file
  • output image file
  • OS version on which this code was executed
  • JDK version

Maybe you have misunderstood what I mean. I think aspose has done a good job, but now I want to reduce the quality of the jpg images produced to reduce the size of the generated images, so is there any better way?

@zyx,
Thank you for the additional information. I will answer you as soon as possible.

@zyx,
To reduce the quality of JPG images, please try to use the next way:

Presentation presentation = new Presentation(dataPath + "in.pptx");
ISlide slide = presentation.getSlides().get_Item(0);
BufferedImage image = slide.getThumbnail(2f, 2f);

JPEGImageWriteParam jpegParams = new JPEGImageWriteParam(null);
jpegParams.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
jpegParams.setCompressionQuality(0.1f);

final ImageWriter writer = ImageIO.getImageWritersByFormatName("jpg").next();
writer.setOutput(new FileImageOutputStream(new File(dataPath + "out.jpg")));

writer.write(null, new IIOImage(image, null, null), jpegParams);

Our documentation will be improved later.