简体   繁体   中英

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

I iterate over all pictures in ppt using following,

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()

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. So with the trunk (POI 3.16) the example code would be like this:

@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()); 
    }
}

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