在 javafx 画布中进行手绘时,我无法获得已消除的线条。以下是代码...
import javafx.application.*;
import javafx.event.*;
import javafx.scene.*;
import javafx.scene.canvas.*;
import javafx.scene.control.*;
import javafx.scene.input.*;
import javafx.scene.shape.*;
import javafx.stage.*;
public class Test2 extends Application {
GraphicsContext gc;
public static void main(String[] args) { launch(args); }
private class MouseDragged implements EventHandler<MouseEvent> {
public void handle( MouseEvent e ) {
gc.lineTo( e.getX(), e.getY() );
gc.stroke();
}
}
private class MousePressed implements EventHandler<MouseEvent> {
public void handle( MouseEvent e ) {
gc.moveTo( e.getX(), e.getY() );
}
}
@Override
public void start(Stage stage) {
Canvas canvas = new Canvas(500, 500);
canvas.setOnMouseDragged( new MouseDragged() );
canvas.setOnMousePressed( new MousePressed() );
gc = canvas.getGraphicsContext2D();
gc.setLineCap( StrokeLineCap.ROUND );
gc.setLineJoin( StrokeLineJoin.ROUND );
gc.setLineWidth( 0.1 );
Group root = new Group(canvas);
Scene scene = new Scene(root);
stage.setTitle("Test2");
stage.setScene(scene);
stage.show();
}
}
如果我创建一个摇摆应用程序,我可以提供渲染提示以使其平滑......
g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
如何为画布中的图形上下文提供渲染命中?