简体   繁体   中英

Resize/compress picture using Apache POI hslf - PowerPoint

Hi I build a powerpoint presentation using apache poi and add a lot of images to the presentation.

private void addImage(SlideShow slideShow, Sheet slide, File image, int x, int y, int w, int h) {
    try {
        int idx = slideShow.addPicture(image, Picture.JPEG);
        Picture pict = new Picture(idx);
        pict.setAnchor(new Rectangle(x, y, w, h));
        slide.addShape(pict);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

The function works and I get a ppt presentation in the end, but the ppt file is too big and at another PC I get a heap space error. So I would like to resize / compress my images in the slides. I have four pictures on each slide - so they don't need to have the original resolution.

Is there a build in function in poi to do this? Something like

pict.resize(width, height);

I'm using apache poi 3.7

thx in advance

POI doesn't modify the pictureData itself. You'll need to resample it yourself before.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM