Joker
Joker

Reputation: 755

what is the draw(java.awt.Graphics2D graphics) method equivalent in android?

I am Working on PowerPointPresentation(.ppt) to convert .ppt files to .png images in ANDROID PLATFORM. To implement this i use Apache Poi Api. In the slide class, there is a method draw(java.awt.Graphics2D graphics) where the parameter passed is Graphics2D.But In Android this class is not supported, instead we use canvas.My question is this,that is there any equivalent draw(java.awt.Graphics2D graphics) method for Android because in the negative case i have to re-write the Api. So give me the best suggestions for this code here

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");
}

}

Upvotes: 1

Views: 2698

Answers (1)

user717572
user717572

Reputation: 3652

Android has the Canvas class, which is very similar to the java's Graphics2D. Look at this link.

(if i understand you correctly)

Upvotes: 2

Related Questions