我一直试图在网上找到一种方法来做这件事,但我什么也找不到。
我想用JavaFX GraphicsContext画一个“反圆圈”。这些图片显示了我想要的东西。
原件:

使用"Inverted Circle“(我想画的):

在图像编辑器中,我可以删除新图层中的圆圈区域。我在GraphicsContext中看不到任何能做到这一点的函数。
我需要能够选择这个“圆”的中心点和半径。
谢谢!
发布于 2017-01-13 13:21:45
我不太确定是否可以直接使用GraphicsContext,但您可以使用Blending来实现。
ImageView image; // Your image
Circle mask = new Circle();
Group g = new Group();
g.setBlendMode(BlendMode.SRC_ATOP);
g.getChildren.add(image);
g.getChildren.add(mask);发布于 2017-01-13 16:14:25
创建一个圆形路径,并在绘制图像时将其用作剪辑:
@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();
}https://stackoverflow.com/questions/41627280
复制相似问题