当前位置: 首页 > 知识库问答 >
问题:

围绕自定义点旋转javafx图像视图

郭俊拔
2023-03-14

当我尝试使用旋转图像视图时,我现在开始学习JavaFX

imgv.setRotate(angle);

它绕着它的中轴线旋转,但是当我尝试使用

imgv.getTransforms().add(new Rotate(Angle,custom_x,custom_y);

它随机旋转,我不知道它的旋转轴是一样的

 imgv.getTransforms().add(new Rotate(Angle,custom_x,custom_y,1.0,Rotate.Z_AXIS);

共有1个答案

邰伟彦
2023-03-14

这里有一个应用程序,演示如何完成你的要求。实现这一点的关键部分是<代码>。getTransforms()。添加(…) 和旋转。代码中的注释。我添加了圆,这样你就可以看到旋转点的位置。

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.transform.Rotate;
import javafx.stage.Stage;

/**
 *
 * @author blj0011
 */
public class JavaFXApplication117 extends Application
{

    @Override
    public void start(Stage primaryStage)
    {
        Image image = new Image("http://lmsotfy.com/so.png");

        ImageView imageView = new ImageView(image);
        imageView.setFitHeight(400);
        imageView.setFitWidth(400);
        Button btn = new Button();
        btn.setText("Say 'Hello World'");

        //Use this Circle to help see where the rotation occurs
        Circle circle = new Circle(5);
        circle.setFill(Color.RED);
        circle.setCenterX(100);
        circle.setCenterY(300);

        //Add the Rotate to the ImageView's Transforms
        Rotate rotation = new Rotate();
        rotation.setPivotX(circle.getCenterX());//Set the Pivot's X to be the same location as the Circle's X. This is only used to help you see the Pivot's point
        rotation.setPivotY(circle.getCenterY());//Set the Pivot's Y to be the same location as the Circle's Y. This is only used to help you see the Pivot's point
        imageView.getTransforms().add(rotation);//Add the Rotate to the ImageView

        //Use the Button's handler to rotate the ImageView
        btn.setOnAction((ActionEvent event) -> {
            rotation.setAngle(rotation.getAngle() + 15);
        });

        Pane pane = new Pane();
        pane.getChildren().addAll(imageView, circle);
        VBox.setVgrow(pane, Priority.ALWAYS);

        VBox vBox = new VBox(pane, new StackPane(btn));

        StackPane root = new StackPane();
        root.getChildren().add(vBox);

        Scene scene = new Scene(root, 1080, 720);

        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        launch(args);
    }

}
 类似资料:
  • 问题内容: 我有一个512x512像素的2D图像,我想在某个原点(旋转中心)以某个角度旋转。一直以来,我都使用Scipy的旋转方法来旋转图像。但是,我迷迷糊糊,因为旋转始终围绕图像的中心进行。对于512x512像素,旋转中心应围绕点(x,y)128,128。如何使用自定义旋转中心旋转图像,比方说(x,y)20,128? 问题答案: 如果不能使用OpenCV,则可以使用NumPy()和SciPy()

  • 问题内容: 将转盘旋转到半圆形(北半球)图像的顶部作为背景。范围可以是0-180度。输入进行画布转换的方法时,刻度盘将旋转并停在匹配的值上。这是我根据phrogz传递的帮助和示例进行的尝试 问题答案: 通常,您要执行的操作是: 将上下文转换为画布上对象应旋转的点。 旋转上下文。 通过对象内旋转中心的负偏移来转换上下文。 在0,0处绘制对象。 在代码中: 这是一个实际的示例,展示了这一点。(旋转的数

  • 问题内容: 有没有一种简单的方法可以围绕图片中心旋转图片?我首先使用了AffineTransformOp。看起来很简单,而且需要,并且在一个整洁的Google会话中为矩阵找到正确的参数。所以我认为… 我的结果是这样的: 如果您忽略旋转90度的倍数的情况,这非常简单(sin()和cos()无法正确处理)。该解决方案的问题在于,它围绕图片左上角的(0,0)坐标点进行变换,而不是围绕图片中心进行正常的变

  • 问题内容: 我已经在这个问题上进行了很多搜索,但是我找不到真正合适的答案。 我需要围绕给定点(例如0,0,0)旋转圆柱体,但是默认情况下会给出圆柱体的枢轴。我该如何改变? 为了更好地说明我想做什么,我将显示3张图像。 imageshack.us/photo/my-images/259/aintgood.jpg imageshack.us/photo/my-images/840/whatineed.

  • 到目前为止,我一直在使用 以旋转 OMR 应用程序的图像。结果是一个旋转但模糊的图像。我也怀疑这会围绕其中心旋转图像。如何将特定的像素位置指定为旋转中心?

  • 我刚开始使用JavaFX,有一个问题。在我的项目中,我想使用旋转矩形。但矩形只围绕其中心旋转,我希望它围绕其左上角旋转。 就像这张照片(从这里开始): 下面是我的项目中的一些代码: 在这种情况下,如果按下箭头键,矩形会旋转。