2

按照http://poi.apache.org/slideshow/how-to-shapes.html提供的示例,我得到了转换工作。

FileInputStream is = new FileInputStream("slideshow.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, BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics = img.createGraphics();

    graphics.setPaint(Color.white);
    graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));
    slide[i].draw(graphics);
    FileOutputStream out = new FileOutputStream("slide-"  + (i+1) + ".png");
    javax.imageio.ImageIO.write(img, "png", out);
    out.close();
}

但是生成的图像非常小。如何增加图像输出的大小?

4

1 回答 1

3

您需要调整图形上下文的大小并添加常规转换。

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

    double zoom = 2; // magnify it by 2
    AffineTransform at = new AffineTransform();
    at.setToScale(zoom, zoom);

    Dimension pgsize = ppt.getPageSize();

    Slide[] slide = ppt.getSlides();
    for (int i = 0; i < slide.length; i++) {
        BufferedImage img = new BufferedImage((int)Math.ceil(pgsize.width*zoom), (int)Math.ceil(pgsize.height*zoom), BufferedImage.TYPE_INT_RGB);
        Graphics2D graphics = img.createGraphics();
        graphics.setTransform(at);

        graphics.setPaint(Color.white);
        graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));
        slide[i].draw(graphics);
        FileOutputStream out = new FileOutputStream("slide-" + (i + 1) + ".png");
        javax.imageio.ImageIO.write(img, "png", out);
        out.close();
    }
于 2013-04-28T10:05:21.027 回答