Apache POI ppt. How to resize and center images on a slide
We have an application that has a gallery function and we would like to export images to a PowerPoint presentation. I was able to do this, but since the images come in different sizes and orientations, almost always the borders of the images come out of the ppt slide. How do I resize the images (I don't want to physically resize them, just add them to the size). And center it on the slide.
Thank,
+3
source to share
1 answer
You can resize the image before adding it to the 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();
}
0
source to share