Silverlight 中MatrixTransform和其他Transform的数值转换
对各种transform的讲解已经很多了,但是有时MatrixTransform和其他transform变换效果之间需要转换时,变换量的转换又如何呢?下面的类就完成了Matrix和其他transform的转换方法。
public static ScaleTransform GetScaleByMatrix(Matrix matrix)
{
ScaleTransform scaleTransform = new ScaleTransform();
scaleTransform.ScaleX = matrix.M22;
scaleTransform.ScaleY = matrix.M11;
return scaleTransform;
}
public static double GetRotateByMatrix(Matrix matrix)
{
double rotate = Math.Acos(matrix.M11);
return rotate;
}
public static TranslateTransform GetTranslateByMatrix(Matrix matrix)
{
TranslateTransform translate = new TranslateTransform();
translate.X = matrix.OffsetX;
translate.Y = matrix.OffsetY;
return translate;
}
public static Matrix GetMatrixByScale(ScaleTransform scale)
{
return new Matrix(scale.ScaleY, , , scale.ScaleX, , );// x or y ???
}
public static Matrix GetMatrixByRotate(double rotate)
{
return new Matrix(Math.Cos(rotate), -Math.Sin(rotate), Math.Sin(rotate), Math.Cos(rotate), , );
}
public static Matrix GetMatrixByTranslate(TranslateTransform translate)
{
return new Matrix(, , , , translate.X, translate.Y);
}
在二位平面的平移变换中, TranslateTransform中的 X 和 Y 值分别对用MatrixTransform 中的OffsetX 和OffsetY, 但是对于RotateTransform 进行平面旋转的时候,他的三个参数Angle,CenterX,CenterY怎么对应到MatrixTransform中呢?在上面的函数 GetMatrixByRotate(a)可以把角度映射到Matrix中,但如果这做了Angle的转换,图片的旋转是默认的左上角点,但是我们的需求并不是左上角,那怎么按照我们设定的centerX 和CenterY来旋转呢?经过研究,找到一个比较笨拙的办法,目前还未找到更好的算法。
private Matrix GetMatrixByPrimaryCenterRotate(Point primaryCenter, Matrix target)
{
MatrixTransform mt = new MatrixTransform() { Matrix = target };
Point newCenter = mt.Transform(primaryCenter);
target.OffsetX = primaryCenter.X - newCenter.X;
target.OffsetY = primaryCenter.Y - newCenter.Y;
return target;
}
通过GetMatrixByRotate(a)方法我们可以计算出旋转angle后的Matrix,然后通过translateTransform 把旋转对象移回到中心旋转的效果,上面的方法可以计算出指定旋转中心的旋转效果。
对于同时进行ScaleTransform和RotateTransform的效果怎么计算呢?
对这样的效果我们对得到的不同的Matrix进行矩阵相乘即可得到混合变换合并之后的MatrixTransform.
See Also: http://msdn.microsoft.com/en-us/library/8667dchf(v=vs.110).aspx
Silverlight 中MatrixTransform和其他Transform的数值转换的更多相关文章
- Silverlight中动画的性能浅析
Silverlight中提供了StoryBoard实现动画,可是StoryBoard的性能实在不敢恭维,特别是动画很大的时候,计算机的CPU和内存的狂增,如此一来性能实在太差,在默认的动画效果中动画实 ...
- Silverlight中的拖拽实现的图片上传
原文 http://blog.csdn.net/dujingjing1230/article/details/5443003 在Silverlight中因为可以直接从系统的文件夹里面拖出来一个文件直接 ...
- WPF/Silverlight中图形的平移,缩放,旋转,倾斜变换演示
原文:WPF/Silverlight中图形的平移,缩放,旋转,倾斜变换演示 为方便描述, 这里仅以正方形来做演示, 其他图形从略. 运行时效果图:XAML代码:// Transform.XAML< ...
- 用C3中的animation和transform写的一个模仿加载的时动画效果
用用C3中的animation和transform写的一个模仿加载的时动画效果! 不多说直接上代码; html标签部分 <div class="wrap"> <h ...
- Silverlight中文本框添加回车事件后,换行无法清除的解决方法
在开发Silverlight的项目中,为了更好的用户体验,我们常要给一些控件添加一些快捷键.然而,在Silverlight中当用户回车提交后,光标停留在文本框的第二行怎么也清除不掉,经过一段时间研究, ...
- SharePoint 2013 Silverlight中使用Net客户端对象模型
1.创建Silverlight时,选择Silverlight 4,不要选择版本5,试了很久版本5都调用不了,自己也不知道什么原因,谷歌也没找到答案,后来尝试版本4,可以调用: 至于Host the S ...
- Silverlight中的TabControl如何绑定数据?重写tabcontrol和tabItem 解决绑定友好问题。可以绑定对象集合
在 WPF 中,TabControl 可以直接将 ItemsSource 绑定数据源,见 将 TabControl 绑定到数据的示例 http://msdn.microsoft.com/zh-cn/l ...
- ArcGIS API for Silverlight中加载Google地形图(瓦片图)
原文:ArcGIS API for Silverlight中加载Google地形图(瓦片图) 在做水利.气象.土地等行业中,若能使用到Google的地形图那是再合适不过了,下面就介绍如何在ArcGIS ...
- 在Silverlight中实施RESTful调用
在Silverlight中实施RESTful调用: http://book.51cto.com/art/201006/206314.htm http://bbs.csdn.net/topic ...
随机推荐
- HTTP状态码的意义
100系列码 从100到199范围的HTTP状态码是信息报告码.基于各种原因考虑,大多数情况下我们是 很少看见这些代码的.首先,如果一个浏览器尝试访问一个网站,而网站返回这些代码时,它们往往都不会显示 ...
- 简单使用JSON,JavaScript读取JSON文本(三)
JavaScript 读取 JSON 文本转换为对象 JSON 最常见的用法之一,是从 web 服务器上读取 JSON 数据(作为文件或作为 HttpRequest),将 JSON 数据转换为 Jav ...
- JS放大镜特效(兼容版)
原理 1.鼠标在小图片上移动时,通过捕获鼠标在小图片上的位置,定位大图片的相应位置 设计 1.页面元素:小图片.大图片.放大镜 2.技术点:事件捕获.定位 1)onmouseover:会在鼠标指针移动 ...
- HTML如何转XTML
ob_start(); $html = curl_init('http://www.beijing.gov.cn/'); curl_exec($html); $html = iconv('GBK',' ...
- Hamilton
import java.util.Vector; class Hamilton { int start; int a[][]; int len; int x[]; // 记录回路 boolean fl ...
- hdu 4561 模拟小题
连续最大积 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Subm ...
- C#中数组,ArrayList与List对象的区别
在C#中,当我们想要存储一组对象的时候,就会想到用数组,ArrayList,List这三个对象了.那么这三者到底有什么样的区别呢? 我们先来了解一下数组,因为数组在C#中是最早出现的. 数组 数组有很 ...
- BIOS详解:什么是BIOS ?BIOS的作用?CMOS及其与BIOS的关系?
1.什么是BIOS ? BIOS是英文Basic Input Output System的缩略语,直译过来后中文名称就是基本输入输出系统.它的全称应该是ROM-BIOS,意思是只读存储器基本输入输出系 ...
- 浅析CDN存在的必要性
CDN行业从出现至今,已经有近20年的历史.但是直到近些年互联网进入超高速发展阶段,CDN才得以得到更广泛的应用和发展.最开始,CDN的主要任务只是简单的内容分发,对于静态内容的加速没有问题.但是随着 ...
- Url以.(点)结尾,在使用httpwebrequest读取的时候,微软会有一个bug……
解决方法在此,不重复做赘述,传送门:http://stackoverflow.com/questions/856885/httpwebrequest-to-url-with-dot-at-the-en ...