1

I am trying to read in a power point image to java for display on a userform.

I am not trying export the entire slide as an image. I need to access the just the image that have been inserted on to the slide.

I have tried the following code and I feel like I am really close but ImageIO.read is returning null.

public BufferedImage getImage2() {
    java.io.InputStream fin = null;
    try {
        PackageRelationship packRel = mySlide.getPackagePart().getRelationship(myName);
        PackagePart part = packRel.getSource();
        fin = part.getInputStream();
        BufferedImage imBuff = ImageIO.read(fin);
        return imBuff;
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    } finally {
        try {
            fin.close();
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
    return null;
}

If anyone has had any experience trying to do this it would be greatly appreciated. Thank you

emmistar
  • 101
  • 10
  • What is "power point image"? `ImageIO` may not support it. – MikeCAT Feb 29 '16 at 08:42
  • It is an image added to a presentation stored in a powerpoint zip file. It is generally jpeg, png etc. – emmistar Feb 29 '16 at 08:45
  • I would love it if it was however I am not trying to extract the entire slide as an image, I already have that in my code. I am trying to get the image that has been placed on the slide and read in that precise image. – emmistar Feb 29 '16 at 09:00

1 Answers1

1

Try something like this:

for(XSLFShape shape : mySlide){
    if (shape instanceof XSLFPictureShape){
        XSLFPictureShape pShape = (XSLFPictureShape)shape;
        XSLFPictureData pData = pShape.getPictureData();
        InputStream pIs = pData.getInputStream();
        // ...
    }
}

More details in the xslf data extraction example.

isalgueiro
  • 1,973
  • 16
  • 20