本文整理匯總了Java中javafx.scene.canvas.GraphicsContext.setLineCap方法的典型用法代碼示例。如果您正苦於以下問題:Java GraphicsContext.setLineCap方法的具體用法?Java GraphicsContext.setLineCap怎麽用?Java GraphicsContext.setLineCap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javafx.scene.canvas.GraphicsContext
的用法示例。
在下文中一共展示了GraphicsContext.setLineCap方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: start
import javafx.scene.canvas.GraphicsContext; //導入方法依賴的package包/類
@Override
public void start(Stage stage) throws Exception {
Canvas canvas = new Canvas(CANVAS_WIDTH, CANVAS_HEIGHT);
ImageView imgView = new ImageView();
GraphicsContext ctx = canvas.getGraphicsContext2D();
model = ModelSerializer.restoreMultiLayerNetwork(new File("minist-model.zip"));
loader = new NativeImageLoader(28,28,1,true);
imgView.setFitHeight(100);
imgView.setFitWidth(100);
ctx.setLineWidth(10);
ctx.setLineCap(StrokeLineCap.SQUARE);
lblResult = new Label();
HBox hbBottom = new HBox(10, imgView, lblResult);
VBox root = new VBox(5, canvas, hbBottom);
hbBottom.setAlignment(Pos.CENTER);
root.setAlignment(Pos.CENTER);
Scene scene = new Scene(root, 520, 300);
stage.setScene(scene);
stage.show();
stage.setTitle("Handwritten digits recognition");
canvas.setOnMousePressed(e -> {
ctx.setStroke(Color.WHITE);
ctx.beginPath();
ctx.moveTo(e.getX(), e.getY());
ctx.stroke();
});
canvas.setOnMouseDragged(e -> {
ctx.setStroke(Color.WHITE);
ctx.lineTo(e.getX(), e.getY());
ctx.stroke();
});
canvas.setOnMouseClicked(e -> {
if (e.getButton() == MouseButton.SECONDARY) {
clear(ctx);
}
});
canvas.setOnKeyReleased(e -> {
if(e.getCode() == KeyCode.ENTER) {
BufferedImage scaledImg = getScaledImage(canvas);
imgView.setImage(SwingFXUtils.toFXImage(scaledImg, null));
try {
predictImage(scaledImg);
} catch (Exception e1) {
e1.printStackTrace();
}
}
});
clear(ctx);
canvas.requestFocus();
}