简体   繁体   English

如何使用poi ppt中java.awt.Dimension中的getImageDimensionInPixels()获取图像大小?

[英]How to get image size using getImageDimensionInPixels() from java.awt.Dimension in poi ppt?

I iterate over all pictures in ppt using following, 我使用以下命令遍历ppt中的所有图片,

for(XSLFPictureData data : ppt.getAllPictures()){
    byte[] bytes = data.getData();
    String fileName = data.getFileName();       
    int pictureFormat = data.getPictureType();                         
    System.out.println("picture : " + fileName); 
    System.out.println("pictureSize : " + data.getImageDimensionInPixels()); 
}

As described in doc: Documentation POI getImageDimensionInPixels() 如doc中所述: 文档POI getImageDimensionInPixels()

How to use this method to get image size in pixels or height/length? 如何使用此方法获取以像素为单位的图像大小或高度/长度?

I've made quite a few changes to unify the HSLF and XSLF API to Common SL - and before you might complain about breaking changes, neither XSLF nor HSLF are in the stable main jar. 我进行了很多更改,以将HSLF和XSLF API统一到Common SL-在您可能抱怨无法更改之前,XSLF和HSLF都不在稳定的主jar中。 So with the trunk (POI 3.16) the example code would be like this: 因此,如果使用中继(POI 3.16),示例代码将如下所示:

@Test
public void bugbla() throws Exception {
    XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("51187.pptx");
    for(XSLFPictureData data : ppt.getPictureData()){
        byte[] bytes = data.getData();
        String fileName = data.getFileName();       
        PictureType pictureFormat = data.getType();                         
        System.out.println("picture : " + fileName); 
        System.out.println("pictureSize : " + data.getImageDimensionInPixels()); 
    }
}

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

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