3

We have an application that has a gallery feature and we would like to export the images to a powerpoint presentation. I was able to do this but as the images come in diferente sizes and orientations, almost always the images bounds go out of the ppt slide. How can I resize the image (I dont want to physically resize them, just add them resized to the slide). And center it on the slide.

Thanks,

Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186
Eduardo Mayer
  • 359
  • 1
  • 3
  • 10

1 Answers1

1

You can resize the image before adding into slide.

private static byte[] resizeImage(byte[] fileData, Integer img_width, Integer img_height) throws IOException{
    ByteArrayInputStream in = new ByteArrayInputStream(fileData);

    BufferedImage originalImage = ImageIO.read(in);
    int type = originalImage.getType() == 0? BufferedImage.TYPE_INT_ARGB
            : originalImage.getType();

    if(img_height == 0){
        img_height = originalImage.getHeight();
    }

    BufferedImage resizedImage = new BufferedImage(img_width, img_height, type);
    Graphics2D g = resizedImage.createGraphics();
    g.drawImage(originalImage, 0, 0, img_width, img_height, null);
    g.dispose();

    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    ImageIO.write(resizedImage, "png", buffer);
    return buffer.toByteArray();
}
Narayan Subedi
  • 1,343
  • 2
  • 20
  • 46