Java:在图像上应用几何变换的文本

Java:在图像上应用几何变换的文本,java,javafx,javafx-2,Java,Javafx,Javafx 2,我知道可以使用BufferedImage的getGraphics在图像上应用标准文本: Graphics g = image.getGraphics(); g.setFont(g.getFont().deriveFont(30f)); g.drawString("Hello World!", 100, 100); g.dispose() 我正在尝试创建一个应用程序,在该应用程序中,我将能够应用带有几何变换(例如旋转、剪切、投影)的文本,以便最终获得如下图像: 是否有一种通用的方法来应用带有几

我知道可以使用
BufferedImage
getGraphics
在图像上应用标准文本:

Graphics g = image.getGraphics();
g.setFont(g.getFont().deriveFont(30f));
g.drawString("Hello World!", 100, 100);
g.dispose()
我正在尝试创建一个应用程序,在该应用程序中,我将能够应用带有几何变换(例如旋转、剪切、投影)的文本,以便最终获得如下图像:

是否有一种通用的方法来应用带有几何变换的文本,如上图所示?

自Java 8以来,JavaFX被视为“标准”,并且内置了易于使用的功能。您可以将任何变换应用于对象,并使用a将其放置在图像顶部

public class MyApp extends Application {

    @Override
    public void start(Stage stage) throws Exception {

        ImageView lena = new ImageView(new Image("main/Lenna.png")); //URL to image

        Text text1 = new Text("Hello World!");
        text1.setRotate(30);
        text1.setTranslateX(100);
        text1.setTranslateY(-100);
        text1.setFont(Font.font("Veranda", FontWeight.BOLD, 36));
        text1.setFill(Color.BLUE);

        Text text2 = new Text("Hello Lenna!");
        PerspectiveTransform perspectiveTrasform = new PerspectiveTransform();
        perspectiveTrasform.setUlx(10);
        perspectiveTrasform.setUly(10);
        perspectiveTrasform.setUrx(300);
        perspectiveTrasform.setUry(40);
        perspectiveTrasform.setLrx(300);
        perspectiveTrasform.setLry(60);
        perspectiveTrasform.setLlx(10);
        perspectiveTrasform.setLly(90);
        text2.setEffect(perspectiveTrasform);
        text2.setFont(Font.font("Veranda", FontWeight.BOLD, 36));

        StackPane pane = new StackPane(lena, text1, text2);
        Scene scene = new Scene(pane);
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) throws Exception {

        launch(args);
    }
}


有关更多信息,请参见。

您想使用哪一个库,Swing?它可以是Swing或其他任何被认为是令人惊奇的库!非常感谢。你是怎么得到同样的图像的?好奇的