简体   繁体   English

使用Apache POI hslf - PowerPoint调整图片大小/压缩图片

[英]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. 嗨,我使用apache poi构建了一个powerpoint演示文稿,并在演示文稿中添加了大量图像。

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. 该函数有效,最后我得到一个ppt演示文稿,但是ppt文件太大而在另一台PC上我得到了堆空间错误。 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? 在poi中是否有功能构建这样做? Something like 就像是

pict.resize(width, height);

I'm using apache poi 3.7 我正在使用apache poi 3.7

thx in advance thx提前

POI doesn't modify the pictureData itself. POI不会修改pictureData本身。 You'll need to resample it yourself before. 您之前需要自己重新取样

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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