gpt4 book ai didi

java - 使用Java将ppt幻灯片提取为图像

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:57:16 25 4
gpt4 key购买 nike

有没有一种方法可以使用 Java 以编程方式将幻灯片拆分为 .png 文件?我四处搜索,给出的大部分答案要么是用 C# 编写的,要么提到的程序不是开源的

最佳答案

为了获得不错的质量,请将以下代码与 Apache POI HSLF 库 ( http://poi.apache.org/slideshow/how-to-shapes.html ) 结合使用:

        FileInputStream is = new FileInputStream("path_to_your.ppt");
SlideShow ppt = new SlideShow(is);
is.close();

Dimension pgsize = ppt.getPageSize();

Slide[] slide = ppt.getSlides();
for (int i = 0; i < slide.length; i++) {

BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, 1);

Graphics2D graphics = img.createGraphics();
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
RenderingHints.VALUE_FRACTIONALMETRICS_ON);

graphics.setColor(Color.white);
graphics.clearRect(0, 0, pgsize.width, pgsize.height);
graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));

// render
slide[i].draw(graphics);

// save the output
FileOutputStream out = new FileOutputStream("slide-" + (i + 1) + ".png");
javax.imageio.ImageIO.write(img, "png", out);
out.close();
}

关于java - 使用Java将ppt幻灯片提取为图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4718709/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com