java Canvas to BufferedImage / Image





6
Date Submitted Sat. Jul. 28th, 2007 3:19 PM
Revision 1 of 1
Helper rugi
Tags BufferedImage | Canvas | Image | Java
Comments 0 comments
Convert
java.awt.Canvas to java.awt.image.BufferedImage or java.awt.image.Image

private BufferedImage canvasToImage(Canvas cnvs) {
        int w = cnvs.getWidth();
        int h = cnvs.getHeight();
        int type = BufferedImage.TYPE_INT_RGB;
        BufferedImage image = new BufferedImage(w,h,type);
        Graphics2D g2 = image.createGraphics();
        cnvs.paint(g2);
        g2.dispose();
        return image;
    }
 

Isaac Ruiz Guerra

weblogs.javahispano.org/rugi/
"non nobis domine"

Comments

There are currently no comments for this snippet.

Voting