淘先锋技术网

首页 1 2 3 4 5 6 7

我正在使用PowerPointPresentation(.ppt)将.ppt文件转换为ANDROID PLATFORM中的.png图像。为了实现这个我使用Apache Poi Api。在slide class中,有一个方法draw(java.awt.Graphics2D graphics),其中传递的参数是Graphics2D。但在Android中,这个类不被支持,而是我们使用canvas。我的问题是这样的,这是Android的任何等效的draw(java.awt.Graphics2D graphics)方法,因为在负面情况下,我必须重新编写Api。所以给我最好的建议,这个代码在这里什么是android中等价的draw(java.awt.Graphics2D图形)方法?

public final class PPT2PNG {

public static void main(String args[]) throws Exception {

File file = new File("C:/Users/THIYAGARAJAN/Desktop/ppt52.ppt");

int scale = 10;

int slidenum = 0;

FileInputStream is = new FileInputStream(file);

SlideShow ppt = new SlideShow(is);

is.close();

Dimension pgsize = ppt.getPageSize();

int width = (int) (pgsize.width * scale);

int height = (int) (pgsize.height * scale);

System.out.println("w" + width + "h" + height);

Slide[] slide = ppt.getSlides();

System.out.println(slide.length);

for (int i = 0; i < slide.length; i++) {

String title = slide[i].getTitle();

System.out.println("Rendering slide " + slide[i].getSlideNumber() + (title == null ? "" : ": " + title));

BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

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.setPaint(Color.white);

graphics.fill(new Rectangle2D.Float(0, 0, width, height));

graphics.scale((double) width/pgsize.width, (double) height/pgsize.height);

slide[i].draw(graphics);

//String fname = file.getAbsolutePath() .replaceAll(".ppt", "-" + (i+1) + ".png");

File fname = new File("C:/Users/THIYAGARAJAN/Desktop/" + i + ".png");

FileOutputStream out = new FileOutputStream(fname);

ImageIO.write(img, "png", out);

out.close();

}

}

private static void usage() {

System.out.println("Usage: PPT2PNG [-scale -slide ] ppt");

}

}

2012-01-21

Thiyagu