我开始测试如何将ppt文档转换为jpeg或png图像。我使用java进行测试。遵循apache web上的说明:http://poi.apache.org/slideshow/how-to-shapes.html#Render,以及代码:
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();
//clear the drawing area
graphics.setPaint(Color.white);
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();
}在ppt文档中,我只需输入"hello world",然后运行java程序,就会成功生成png图像。但是我用ACDsee软件打开图像来查看图像,但是"helloworld“并没有出现在png图像中。出什么事了?在座的各位能给我一些建议吗?你也可以自己测试,看看结果,如果你得到了同样的结果,请让我知道。
发布于 2012-06-04 01:52:11
看起来你根本没有用你的BufferedImage做任何事情。您只需用白色填充图像并将其保存到文件中。
https://stackoverflow.com/questions/10871982
复制相似问题