如何将任何文本或字母转换为javafx中的图像

dre*_*pol 3 java text javafx image

例如,我有文字,写的是字母或句子.如何将此文本转换为javafx中的图像,然后将其显示为图像.我无法使用标签,因为我需要有可能编辑此转换图像的任何像素.

有人能给我建议吗?

Jam*_*s_D 8

private WritableImage textToImage(String text) {

    Text t = new Text(text);
    Scene scene = new Scene(new StackPane(t));
    return t.snapshot(null, null);
}
Run Code Online (Sandbox Code Playgroud)