円形経路を構築して画像を描画するときにクリップとしてそれを使用する:
@Override
public void start(Stage primaryStage) {
Image image = new Image("https://i.stack.imgur.com/zEoW1.jpg");
double w = image.getWidth();
double h = image.getHeight();
Canvas canvas = new Canvas(w, h);
GraphicsContext gc = canvas.getGraphicsContext2D();
// draw background
gc.setFill(Color.BLACK);
gc.fillRect(0, 0, w, h);
double r = Math.min(h, w) * 2/5;
double cx = w/2;
double cy = h/2;
// create circular path
gc.beginPath();
gc.moveTo(cx - r, cy); // to first point on the circle
gc.arc(cx, cy, r, r, 180, 360);
gc.closePath();
gc.clip();
gc.drawImage(image, 0, 0);
StackPane root = new StackPane();
root.getChildren().add(canvas);
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}
私はこれを使用しますが、残念ながら私はゲームを作っていますので、私はキャンバスに – MCMastery
@MCMasteryを使用していますおそらくFabianの方法が好まれますが、 'GraphicsContext'は[BlendMode]をサポートしています(http://docs.oracle.com/javase/8/javafx/api/javafx/scene/canvas/GraphicsContext.html#setGlobalBlendMode-javafx.scene.effect .BlendMode-)も同様です。あなたが解決策から外れているなら、それを見てみることができます。 – Jai