【发布时间】:2021-09-07 23:14:12
【问题描述】:
我目前正在做一个项目,用户可以绘制图像,然后一个小型神经网络猜测绘制的图像(在 Java 中,相信我,我想用 Python 来做)。 为此,我使用快照导出了画布。现在我想将 a 居中并裁剪为固定大小,比如说 50x50 像素。 Java有这方面的方法吗?
public void guess(ActionEvent actionevent) {
SnapshotParameters params = new SnapshotParameters();
params.setFill(Color.TRANSPARENT);
WritableImage image = new WritableImage((int)canvas.getWidth(),(int)canvas.getHeight());
image = canvas.snapshot(params, null);
BufferedImage bufferedImage = new BufferedImage((int)image.getWidth(),(int)image.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
bufferedImage = SwingFXUtils.fromFXImage(image, null);
String str = NNInterface.initNN(bufferedImage);
outputText.setText(str);
}
}
否则我不得不使用双数组或smth。
谢谢
【问题讨论】:
标签: java image bufferedimage snapshot