我无法弄清楚如何制作节点组的快照。也就是说,我想制作一个覆盖有数字的PNG图标图像(例如未读消息)。
我的代码:
int totalNumberOfUnreadMessages = 1;
ImageView applicationIconImageView = new ImageView(getApplication().getStage().getIcons().get(1));
Text text = new Text();
text.setX(10);
text.setY(10);
text.setFill(Color.RED);
text.setText(Integer.toString(totalNumberOfUnreadMessages));
text.setFont(Font.font(null, FontWeight.BOLD, 10));
Group group = new Group();
group.getChildren().addAll(applicationIconImageView, text);
MainFrameWindow.runOnUIThread(() -> {
getApplication().getStage().getIcons().clear();
WritableImage applicationIconWritableImage = group.snapshot(new SnapshotParameters(), null);
getApplication().getStage().getIcons().add(0, applicationIconWritableImage);
}, false);
非常感谢任何帮助。 提前谢谢大家。
答案 0 :(得分:1)
BufferedImage bufferedImage = new BufferedImage(dimension, dimension, BufferedImage.TYPE_INT_ARGB);
SwingFXUtils.fromFXImage(scene.snapshot(new WritableImage(dimension, dimension)), bufferedImage);
SwingFXUtils.toFXImage(bufferedImage, new WritableImage(dimension, dimension));