📅  最后修改于: 2020-10-14 01:51:42             🧑  作者: Mango
缩放是一种转换,用于更改对象的大小。它可以扩大或缩小对象的大小。可以通过将对象的坐标乘以一个称为比例因子的因子来更改大小。在JavaFX中,类javafx.scene.transform.Scale表示缩放转换。
在下图中,缩放变换应用于多维数据集以扩展其大小。
下表描述了该类的属性。
Property | Description | Setter Methods |
---|---|---|
pivotX | It is a double type property. It represents the x coordinate of the pivot point about which the scaling is done. | setPivotX(double value) |
pivotY | It is a double type property. It represents the y coordinate of the pivot point about which the scaling is done. | setPivotY(double value) |
pivotZ | It is a double type property. It represents the z coordinate of the pivot point about which the scaling is done. | setPivotZ(double value) |
x | It is a double type property. It represents the factor by which the object is scaled along the X axis. | setX(double value) |
y | It is a double type property. It represents the factor by which the object is scaled along the Y axis. | setY(double value) |
z | It is a double type property. It represents the factor by which the object is scaled along the Z axis. | setZ(double value) |
该类包含以下描述的五个构造函数。
以下示例说明了缩放转换的实现。在这里,我们创建了两个具有相同尺寸和颜色的圆。将缩放转换应用于第二个圆,以使其在XY方向上均按因子1.5缩放。将缩放变换应用于第二个圆后,它将获得第一个圆的1.5。
package application;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.scene.transform.Scale;
import javafx.stage.Stage;
public class ScaleExample extends Application{
@Override
public void start(Stage primaryStage) throws Exception {
// TODO Auto-generated method stub
//Creating the two circles
Circle cir1=new Circle(230,200,100);
Circle cir2=new Circle(550,200,100);
//setting the color and stroke for the circles
cir1.setFill(Color.YELLOW);
cir1.setStroke(Color.BLACK);
cir2.setFill(Color.YELLOW);
cir2.setStroke(Color.BLACK);
// creating the text nodes for the identification
Text text1 = new Text("Original Circle");
Text text2 = new Text("Scaled with factor 1.5 in XY");
//setting the properties for the text nodes
text1.setX(150);
text1.setY(400);
text2.setX(400);
text2.setY(400);
text1.setFont(Font.font("calibri",FontWeight.BLACK,FontPosture.ITALIC,20));
text2.setFont(Font.font("calibri",FontWeight.BLACK,FontPosture.ITALIC,20));
//creating a 2D scale
Scale scale = new Scale();
// setting the X-y factors for the scale
scale.setX(1.5);
scale.setY(1.5);
//setting the pivot points along which the scaling is done
scale.setPivotX(550);
scale.setPivotY(200);
//applying transformations on the 2nd circle
cir2.getTransforms().add(scale);
Group root = new Group();
root.getChildren().addAll(cir1,cir2,text1,text2);
Scene scene = new Scene(root,800,450);
primaryStage.setScene(scene);
primaryStage.setTitle("Scale Example");
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}