的RenderTransform VS PushTransform [英] RenderTransform vs PushTransform

查看:328
本文介绍了的RenderTransform VS PushTransform的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个形状(下面的红色路径)和我都适用于该路径的 TranslateTransform 和的 ScaleTransform 改造。但是,如果我使用图形 <一href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.rendertransform%28v=vs.90%29.aspx"相对=nofollow>的RenderTransform 这样属性:

I have a shape (the red path below) and i have to apply to this path a TranslateTransform and a ScaleTransform transformation. But if i use the Shape RenderTransform property in this way:

Path MyPath = new Path { Fill = new SolidColorBrush(Colors.Red) };
MyPath.Data = MyPathGeometry;
TransformGroup transf = new TransformGroup();
transf.Children.Add(new TranslateTransform(50, 50));
transf.Children.Add(new ScaleTransform(2, 2));
MyPath.RenderTransform = transf;

我得到这个类型的图:

I get a drawing of this type:

相反,如果我使用的DrawingContext <一href="http://msdn.microsoft.com/en-us/library/system.windows.media.drawingcontext.pushtransform%28v=vs.90%29.aspx"相对=nofollow> PushTransform 这样的方法:

Instead, if I use DrawingContext PushTransform method in this way:

DrawingVisual MyPath = new DrawingVisual();

using (DrawingContext context = MyPath.RenderOpen()) {
   context.PushTransform(new TranslateTransform(50, 50));
   context.PushTransform(new ScaleTransform(2, 2));
   context.DrawGeometry(Brushes.Red, null, MyPathGeometry);
}

我得到这个类型的图:

I get a drawing of this type:

为什么两条路径被放置在不同的方式?使用PushTransform和的RenderTransform之间的区别是什么?我怎么能得到同样的结果在这两种情况下? 谢谢你。

Why the two paths are placed in a different way? What is the difference between using PushTransform and RenderTransform? How could i get the same result in both cases? Thanks.

推荐答案

所不同的仅仅是其中的转化应用的顺序。

The difference is simply the order in which the transformations are applied.

在第一种情况下(的TransformGroup),你首先由(50,50)翻译,然后按比例(2,2)。在第二种情况下(PushTransform)你第一次大规模,然后进行转换。

In the first case (TransformGroup) you first translate by (50, 50), then scale by (2, 2). In the second case (PushTransform) you first scale, then translate.

在一个的TransformGroup的转换是在顺序执行时,先入先出的顺序,wheras推入变换被在执行堆栈状或后进先出的顺序

The transformations in a TransformGroup are executed in a sequential, first-in-first-out order, wheras the pushed transforms are executed in a stack-like or last-in-first-out order.

这篇关于的RenderTransform VS PushTransform的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆