3

Rectangle2D.DoubleのようなShapeオブジェクトをImageオブジェクトに変換するにはどうすればよいですか?

このようにして、マウスカーソルの代わりにShapeオブジェクトを使用できます。

4

2 に答える 2

2

Do draw(shape) in a BufferedImage, as shown here.

于 2011-03-27T14:24:28.070 に答える
1

適切な位置に適切なピクセルを含む画像オブジェクトを作成する必要があります。

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

ただし、別のカラー モデルを使用して、白地に黒などではなく、透明な背景でシェイプを表示することもできます。

于 2011-03-27T14:26:16.353 に答える