2012-01-21 57 views
1

我正在使用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 <scale> -slide <num>] ppt"); 
} 

}

回答

2

Android有Canvas類,這是非常類似於Java的Graphics2D的。看看這個link.

(如果我理解正確的話)

+0

我想在機器人上面的代碼中尤其是滑[I] .draw(圖形); – Thiyagu

相關問題