首页 > 其他分享 >12.旋转、缩放、倾斜、平移Transform

12.旋转、缩放、倾斜、平移Transform

时间:2024-02-01 09:00:12浏览次数:28  
标签:12 缩放 double get Transform Value set static public

RotateTransform旋转

RotateTransform表示旋转一个对象的角度。首先我们来看一下它的定义

public sealed class RotateTransform : Transform
{
 
    public static readonly DependencyProperty AngleProperty;
    public static readonly DependencyProperty CenterXProperty;
    public static readonly DependencyProperty CenterYProperty;
 
    public RotateTransform();
    public RotateTransform(double angle);
    public RotateTransform(double angle, double centerX, double centerY);
 
    public double Angle { get; set; }
    public double CenterX { get; set; }
    public double CenterY { get; set; }
    public override Matrix Value { get; }
 
public RotateTransform Clone();
public RotateTransform CloneCurrentValue();
protected override Freezable CreateInstanceCore();
}

Angle属性表示获取或设置顺时针旋转的角度(以度为单位)。默认值是0度。

CenterX 和CenterY 表示获取或设置旋转中心点的 x y坐标,Value属性表示当前转换的矩阵。

通常我们只需要设置Angle、CenterX 和CenterY即可

案列:

 <Button Grid.Column="1" 
                Width="100" 
                Height="25" 
                Content="RotateTransform" 
                HorizontalAlignment="Center" 
                VerticalAlignment="Center">
            <Button.RenderTransform>
                <RotateTransform Angle="{Binding ElementName=slider,Path=Value}" 
                                 CenterX="50" CenterY="12.5"/>
            </Button.RenderTransform>
        </Button>


<Slider x:Name="slider" 
                Grid.ColumnSpan="3" 
                Margin="30" 
                HorizontalAlignment="Left" 
                VerticalAlignment="Bottom" 
                Value="0" 
                Maximum="720" 
                Width="400" />

 

ScaleTransform缩放

ScaleTransform表示在二维xy坐标系内缩放对象。所以它放大缩小的方向只有两个,分别是X方向和Y方向。另外,每个方向上需要设置一个中心点。

public sealed class ScaleTransform : Transform
{
    public static readonly DependencyProperty ScaleXProperty;
    public static readonly DependencyProperty ScaleYProperty;
    public static readonly DependencyProperty CenterXProperty;
    public static readonly DependencyProperty CenterYProperty;
 
    public ScaleTransform();
    public ScaleTransform(double scaleX, double scaleY);
    public ScaleTransform(double scaleX, double scaleY, double centerX, double centerY);
 
    public double ScaleX { get; set; }
    public double ScaleY { get; set; }
    public double CenterX { get; set; }
    public double CenterY { get; set; }
    public override Matrix Value { get; }
 
    public ScaleTransform Clone();
    public ScaleTransform CloneCurrentValue();
    protected override Freezable CreateInstanceCore();
}

ScaleX属性:获取或设置X轴缩放比例。

ScaleY属性:获取或设置Y轴缩放比例。

CenterX属性:获取或设置当前缩放对象的X轴的中心坐标。

CenterY属性:获取或设置当前缩放对象的Y轴的中心坐标。

案例:

<Button Grid.Column="0" 
                Width="100" 
                Height="25" 
                Content="ScaleTransform" 
                HorizontalAlignment="Center" 
                VerticalAlignment="Center">
            <Button.RenderTransform>
                <ScaleTransform ScaleX="{Binding ElementName=sliderX,Path=Value}"
                                ScaleY="{Binding ElementName=sliderY,Path=Value}"/>
            </Button.RenderTransform>
        </Button>       
        
        <Button x:Name="button" 
                Grid.Column="1" 
                Width="100" 
                Height="25" 
                Content="ScaleTransform" 
                HorizontalAlignment="Center" 
                VerticalAlignment="Center">
            <Button.RenderTransform>
                <ScaleTransform CenterX="50" CenterY="12.5"/>
            </Button.RenderTransform>
        </Button>
<Slider x:Name="sliderX" 
                Grid.ColumnSpan="3" 
                Margin="40 25 20 15" 
                HorizontalAlignment="Left" 
                VerticalAlignment="Bottom" 
                Value="1" 
                Maximum="10" 
                Width="400" />
        <Slider x:Name="sliderY" 
                Orientation="Vertical"
                Grid.ColumnSpan="3" 
                Margin="20" 
                HorizontalAlignment="Left" 
                VerticalAlignment="Bottom" 
                Value="1" 
                Maximum="10" 
                Height="300" />

 

SkewTransform倾斜

SkewTransform表示倾斜某个对象,它有两个方向的倾斜角度可以设置,AngleX表示设置x 轴倾斜角度,该角度是从 y 轴逆时针旋转后测量得到,单位为度。AngleY表示设置y 轴倾斜角度,该角度通过测量从 x 轴逆时针旋转得到的角度度数。另外,它也有CenterX和CenterY,表示倾斜转换中心的xy坐标。

public sealed class SkewTransform : Transform
{
   public static readonly DependencyProperty AngleXProperty;
   public static readonly DependencyProperty AngleYProperty;
   public static readonly DependencyProperty CenterXProperty;
   public static readonly DependencyProperty CenterYProperty;
 
   public SkewTransform();
   public SkewTransform(double angleX, double angleY);
   public SkewTransform(double angleX, double angleY, double centerX, double centerY);
 
   public double AngleX { get; set; }
   public double AngleY { get; set; }
   public double CenterX { get; set; }
   public double CenterY { get; set; }
   public override Matrix Value { get; }
 
   public SkewTransform Clone();
   public SkewTransform CloneCurrentValue();
 
}

案例:

<Border Grid.Column="0" 
                Width="120" 
                Height="120" 
                Background="LightBlue"
                HorizontalAlignment="Center" 
                VerticalAlignment="Center">
            <Border.RenderTransform>
                <SkewTransform CenterX="0" CenterY="0"
                               AngleX="{Binding ElementName=sliderX,Path=Value}"
                               AngleY="{Binding ElementName=sliderY,Path=Value}"/>
            </Border.RenderTransform>
        </Border>       
        
        <Button x:Name="button" 
                Grid.Column="1" 
                Background="LightBlue"
                Width="120" 
                Height="120" 
                Content="SkewTransform倾斜" 
                HorizontalAlignment="Center" 
                VerticalAlignment="Center">
            <Button.RenderTransform>
                <SkewTransform CenterX="60" CenterY="60"
                               AngleX="{Binding ElementName=sliderX,Path=Value}"
                               AngleY="{Binding ElementName=sliderY,Path=Value}"/>
            </Button.RenderTransform>
        </Button>
        <Slider x:Name="sliderX" 
                Grid.ColumnSpan="3" 
                Margin="40 25 20 15" 
                HorizontalAlignment="Left" 
                VerticalAlignment="Bottom" 
                Value="0" 
                Maximum="180" 
                Width="400" />
        <Slider x:Name="sliderY" 
                Orientation="Vertical"
                Grid.ColumnSpan="3" 
                Margin="20" 
                HorizontalAlignment="Left" 
                VerticalAlignment="Bottom" 
                Value="0" 
                Maximum="180" 
                Height="300" />

 

TranslateTransform平移

TranslateTransform只有X和Y两个属性,分别代表X轴和Y轴上的平移距离。

public sealed class TranslateTransform : Transform
{
    public static readonly DependencyProperty XProperty;
    public static readonly DependencyProperty YProperty;
 
    public TranslateTransform();
    public TranslateTransform(double offsetX, double offsetY);
 
    public double X { get; set; }
    public double Y { get; set; }
    public override Matrix Value { get; }
 
    public TranslateTransform Clone();
    public TranslateTransform CloneCurrentValue();
 
}

 

案例:

<Border Grid.Column="0" 
                Width="120" 
                Height="120" 
                Background="LightBlue"
                HorizontalAlignment="Center" 
                VerticalAlignment="Center">
            <Border.RenderTransform>
                <TranslateTransform 
                               X="{Binding ElementName=sliderX,Path=Value}"
                               Y="{Binding ElementName=sliderY,Path=Value}"/>
            </Border.RenderTransform>
        </Border>
 
        <Border x:Name="border" 
                Grid.Column="1" 
                Background="LightGreen"
                Width="120" 
                Height="120" 
                HorizontalAlignment="Center" 
                VerticalAlignment="Center">
            <Border.RenderTransform>
                <TranslateTransform/>
            </Border.RenderTransform>
        </Border>
        <Slider x:Name="sliderX" 
                Grid.ColumnSpan="3" 
                Margin="40 25 20 15" 
                HorizontalAlignment="Left" 
                VerticalAlignment="Bottom" 
                Value="0" 
                Maximum="180" 
                Width="400" />
        <Slider x:Name="sliderY" 
                Orientation="Vertical"
                Grid.ColumnSpan="3" 
                Margin="20" 
                HorizontalAlignment="Left" 
                VerticalAlignment="Bottom" 
                Value="0" 
                Maximum="180" 
                Height="300" />

在这个例子中,左边的border的TranslateTransform 对象的值直接绑定到slider,拖动两个slider就可以控制border水平和垂直方向的位置。右边的border则利用鼠标按下、移动和抬起事件,初步实现了用鼠标去移动位置的功能

public partial class MainWindow : Window
{
    public Point DownPoint { get; private set; } = new Point(0, 0);
    public bool IsMouseDown { get; private set; } = false;
    public MainWindow()
    {
        InitializeComponent();
    }
 
    private void Window_MouseMove(object sender, MouseEventArgs e)
    {
        if (!IsMouseDown) return;
 
        if (border.RenderTransform is TranslateTransform t)
        {
            Point point = e.GetPosition(this);
            t.X = (point.X - DownPoint.X);
            t.Y = (point.Y - DownPoint.Y);
        }
    }
 
    private void Window_MouseDown(object sender, MouseButtonEventArgs e)
    {
        IsMouseDown = true;
        DownPoint = e.GetPosition(this);
    }
 
    private void Window_MouseUp(object sender, MouseButtonEventArgs e)
    {
        IsMouseDown = false;
    }
}

 

标签:12,缩放,double,get,Transform,Value,set,static,public
From: https://www.cnblogs.com/MingQiu/p/18000496

相关文章

  • 龙蜥8.6 源码安装python3.12
    ​ 闲来无事用虚拟机安装了一下龙蜥系统。[root@localhosthome]#cat/etc/*release*AnolisOSrelease8.6NAME="AnolisOS"VERSION="8.6"ID="anolis"ID_LIKE="rhelfedoracentos"VERSION_ID="8.6"PLATFORM_ID="platform:an......
  • 11.Transform抽象类
    在WPF框架中有一个抽象类叫Transform,它定义了实现二维平面中的转换的功能。它包括旋转(RotateTransform)、缩放(ScaleTransform)、倾斜(SkewTransform)和平移(TranslateTransform)4个子类。它定义如何将点从一个坐标空间映射或转换到另一个坐标空间。此映射由转换Matrix来......
  • 1231231
    我想看拜年祭呃呃呃呃呃呃我要听古风燃曲我不要听闭眼我触摸幻想的边界这种当然我不是说不好听但是我要听古风燃曲aaaaaaaaaaaaaa蜀黍能不能给点力aaaaaaaaaaaaaaaaaaaaaaaa我要听万古生香我要听权御天下我要听九九八十一我要听万象霜天我要听万神纪推歌:万神纪/星尘by邪叫教主......
  • fastjson 1268-jdbc
    1268-jdbc复现靶场项目是https://github.com/lemono0/FastJsonParty版本{"@type":"java.lang.AutoCloseable"回包:{"timestamp":"2024-01-31T09:45:27.342+0000","status":500,"error":"InternalS......
  • 12.分组并发压测实战
    1.压测计划制定压测策略不同的并发数10,50,100,200,……持续时间30s记录结果测试期望结果验证能够支撑多大并发数,峰值数验证错误率,定义可接受范围,<=0.1%or<=0.5%ormust=0%2.压测策略通过对比并发数与流量还有错误率的关系,找到一个最合理的系统可支撑最......
  • 动力节点RabbitMQ教程|12小时学会rabbitmq消息中间件-02
    RabbitMQ集群cluster与高可用RabbitMQ的集群分两种模式,一种是默认集群模式,一种是镜像集群模式;在RabbitMQ集群中所有的节点(一个节点就是一个RabbitMQ的broker服务器)被归为两类:一类是磁盘节点,一类是内存节点;磁盘节点会把集群的所有信息(比如交换机、绑定、队列等信息)持久化......
  • 李宏毅《机器学习》总结 - Transformer
    前言当时老师要求我做transformer和self-attention的ppt,结果当时在训练ACM没大有时间,就弄了个质量不高的,不出意外的被喷了。。。现在回头看看当时做的整体没有大问题,但是由于知识没有连贯起来导致有些地方没有提到,也没有形成一个比较完整的架构。Transformer能做的任务......
  • 1247-jndi-waf
    1247-jndi-waf复现1.判断既然是Json格式自然优先尝试是否是Fastjson.判断是否为Fastjson:删掉末尾的}或添加",使其解析报错,这样就代表的使用的是fastjson。2.查看版本接下来就是探测版本.有两种方法,通过报错和Dnslog.{"@type":"java.lang.AutoCloseable"从返回包可......
  • 1247-jndi
    Fastjson1247-jndi复现过程依旧是探测一下fastjson的版本,使用:{ "@type":"java.lang.AutoCloseable"关于这种方式探测fastjosn版本,条件是需要response中会回显报错信息,但实际环境可能存在不回显的情况,那就需要利用其他手段了那么已知fastjson版本为1.2.47,那么我们就可......
  • AP8851L DCDC降压恒压输出12V 5V2.5A应用资料及BOM清单
    1.方案特性双层PCB板(L42mm×W25mm×H15mm) 输入电压范围:11V~85V(输出5V)18V~85V(输出12V) 输出电流:2.5A 效率:93.8%(输出12V)2.应用领域 扭扭车控制器 平衡车控制器电动车控制器 快充电源 逆变器系统工业控制系统3方案原理图及工作原理描述 4,AP8851-5......