Javafx 2 Javafx中的旋转图像

Javafx 2 Javafx中的旋转图像,javafx-2,Javafx 2,在Javafx中,ImageView.setRotate(40)使用哪个参考点旋转图像 我在写作 ImageView iv = new ImageView(image); iv.setRotate(40); SnapshotParameters params = new SnapshotParameters(); params.setFill(Color.TRANSPARENT); Image rotatedImage = iv.snapshot(params, null); gc.drawIm

在Javafx中,
ImageView.setRotate(40)
使用哪个参考点旋转图像

我在写作

ImageView iv = new ImageView(image);
iv.setRotate(40);
SnapshotParameters params = new SnapshotParameters();
params.setFill(Color.TRANSPARENT);
Image rotatedImage = iv.snapshot(params, null);
gc.drawImage(rotatedImage, 0, 0);
但图像不会相对于图像中心旋转。

从:

旋转所围绕的轴心点是未转换对象的中心

因此,图像将围绕其中心点旋转

样本:

import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.SnapshotParameters;
import javafx.scene.canvas.Canvas;
import javafx.scene.image.*;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class Rotor extends Application {

    public static final String LOC =
            "http://icons.iconarchive.com/icons/custom-icon-design/flatastic-10/64/Bear-icon.png";

    @Override
    public void start(Stage stage) throws Exception {
        ImageView iv = new ImageView(new Image(LOC));
        iv.setRotate(40);

        SnapshotParameters params = new SnapshotParameters();
        params.setFill(Color.TRANSPARENT);
        Canvas canvas = new Canvas(100, 100);

        Image rotatedImage = iv.snapshot(params, null);
        canvas.getGraphicsContext2D().drawImage(rotatedImage, 0, 0);
        stage.setScene(new Scene(new Group(canvas)));

        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

在画布上绘制旋转图像时,您可能希望使用画布变换而不是快照方法来帮助完成此操作。例如,见: