我们有一个具有图库功能的应用程序,我们想将图像导出到 PowerPoint 演示文稿。我能够做到这一点,但由于图像的大小和方向不同,几乎总是图像边界超出 ppt 幻灯片。如何调整图像大小(我不想物理调整它们的大小,只需将调整大小的它们添加到幻灯片中)。并在幻灯片上居中。
谢谢,
我们有一个具有图库功能的应用程序,我们想将图像导出到 PowerPoint 演示文稿。我能够做到这一点,但由于图像的大小和方向不同,几乎总是图像边界超出 ppt 幻灯片。如何调整图像大小(我不想物理调整它们的大小,只需将调整大小的它们添加到幻灯片中)。并在幻灯片上居中。
谢谢,
您可以在添加到幻灯片之前调整图像大小。
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();
}