Search code examples
javaapache-poipowerpointxslf

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?


Solution

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