2011-03-27 126 views

回答

1

您必须创建一个图像对象,该图像对象在正确的位置包含正确的像素。

一种方法是这样的:

public Image makeImage(Shape s) { 
    Rectangle r = s.getBounds(); 
    Image image = new BufferedImage(r.width, r.height, BufferedImage.TYPE_BYTE_BINARY); 
    Graphics2D gr = image.createGraphics(); 
    // move the shape in the region of the image 
    gr.translate(-r.x, -r.y); 
    gr.draw(s); 
    gr.dispose(); 
    return image; 
} 

您可能需要使用其他颜色模型,但是,让你的造型显示了透明背景,而不是黑色的,白色的或以其他方式周围。