类AffineTransform用于二维平面上坐标变换。可以对坐标进行平移,缩放,旋转等变换。下面例子显示了坐标变换的用法。
private void Transform()
{
Path path;
/* The first matrix */
AffineTransform matrix1 = new AffineTransform();
/* The second matrix */
AffineTransform matrix2 = new AffineTransform();
/* The third matrix */
AffineTransform matrix3 = new AffineTransform();
/** Colors */
Color blackColor = new Color(0xff000000, false);
Color redColor = new Color(0xffff0000, false);
Color greenColor = new Color(0xff00ff00, false);
Color blueColor = new Color(0xff0000ff, false);
Color fillColor = new Color(0x4f0000ff, true);
/* Define the path */
path = new Path();
path.MoveTo(50, 0);
path.LineTo(0, 0);
path.LineTo(0, 50);
/* Define the matrix1 as "translate(50,50)" */
matrix1.Translate(50, 50);
/* Define the matrix2 as "translate(50,50) + rotate(-45)" */
matrix2 = new AffineTransform(matrix1);
AffineTransform m = new AffineTransform();
m.Rotate(-45 * Math.PI / 180.0, 0, 0);
/* Concatenates the m to the matrix2.
* [matrix2] = [matrix2] * [m];
*/
matrix2.Concatenate(m);
/* Define the matrix3 as
* "translate(50,50) + rotate(-45) + translate(-20,80)" */
/* Copy the matrix2 to the matrix3 */
matrix3 = new AffineTransform(matrix2);
m = new AffineTransform();
m.Translate(-20, 80);
/* Concatenates the m to the matrix3.
* [matrix3] = [matrix3] * [m]
*/
matrix3.Concatenate(m);
//Clear the canvas with white color.
graphics2D.Clear(Color.White);
graphics2D.AffineTransform = (matrix1);
SolidBrush brush = new SolidBrush(fillColor);
Pen pen = new Pen(redColor, 4);
graphics2D.SetPenAndBrush(pen, brush);
graphics2D.Draw(null, path);
graphics2D.AffineTransform = (matrix2);
pen = new Pen(greenColor, 4);
graphics2D.SetPenAndBrush(pen, brush);
graphics2D.Draw(null, path);
graphics2D.AffineTransform = (matrix3);
pen = new Pen(blueColor, 4);
graphics2D.SetPenAndBrush(pen, brush);
graphics2D.Draw(null, path);
}
private void Transform()
{
Path path;
/* The first matrix */
AffineTransform matrix1 = new AffineTransform();
/* The second matrix */
AffineTransform matrix2 = new AffineTransform();
/* The third matrix */
AffineTransform matrix3 = new AffineTransform();
/** Colors */
Color blackColor = new Color(0xff000000, false);
Color redColor = new Color(0xffff0000, false);
Color greenColor = new Color(0xff00ff00, false);
Color blueColor = new Color(0xff0000ff, false);
Color fillColor = new Color(0x4f0000ff, true);
/* Define the path */
path = new Path();
path.MoveTo(50, 0);
path.LineTo(0, 0);
path.LineTo(0, 50);
/* Define the matrix1 as "translate(50,50)" */
matrix1.Translate(50, 50);
/* Define the matrix2 as "translate(50,50) + rotate(-45)" */
matrix2 = new AffineTransform(matrix1);
AffineTransform m = new AffineTransform();
m.Rotate(-45 * Math.PI / 180.0, 0, 0);
/* Concatenates the m to the matrix2.
* [matrix2] = [matrix2] * [m];
*/
matrix2.Concatenate(m);
/* Define the matrix3 as
* "translate(50,50) + rotate(-45) + translate(-20,80)" */
/* Copy the matrix2 to the matrix3 */
matrix3 = new AffineTransform(matrix2);
m = new AffineTransform();
m.Translate(-20, 80);
/* Concatenates the m to the matrix3.
* [matrix3] = [matrix3] * [m]
*/
matrix3.Concatenate(m);
//Clear the canvas with white color.
graphics2D.Clear(Color.White);
graphics2D.AffineTransform = (matrix1);
SolidBrush brush = new SolidBrush(fillColor);
Pen pen = new Pen(redColor, 4);
graphics2D.SetPenAndBrush(pen, brush);
graphics2D.Draw(null, path);
graphics2D.AffineTransform = (matrix2);
pen = new Pen(greenColor, 4);
graphics2D.SetPenAndBrush(pen, brush);
graphics2D.Draw(null, path);
graphics2D.AffineTransform = (matrix3);
pen = new Pen(blueColor, 4);
graphics2D.SetPenAndBrush(pen, brush);
graphics2D.Draw(null, path);
}

分享到:
相关推荐
Silverlight示例Silverlight示例Silverlight示例Silverlight示例Silverlight示例Silverlight示例Silverlight示例Silverlight示例Silverlight示例Silverlight示例Silverlight示例Silverlight示例
Silverlight计算机图形学2二维坐标和显示基础.pdf
在本文中,我们将深入探讨如何使用Silverlight技术来实现一个二维旋转、平面渐变和动画效果,以此模拟雷达扫描的视觉...通过分析和学习这段源码,你可以更深入地理解Silverlight中的图形变换、颜色渐变以及动画机制。
**Silverlight 示例详解** Silverlight,由微软公司开发,是一种基于.NET Framework的浏览器插件,旨在增强Web应用程序的媒体体验和交互性。它允许开发者创建丰富的、动态的、交互式的用户界面,支持多媒体播放、2D...
《Silverlight微软一站式示例代码库:中文版源码解析》 Silverlight,作为微软推出的一款基于.NET Framework的浏览器插件,曾广泛应用于富互联网应用(RIA)开发,尤其是在多媒体内容展示、交互式用户界面设计等...
Canvas对象是Silverlight用户界面(UI)构建的基础,它是一个二维绘图区域,支持绝对定位。这意味着你可以精确地控制每个子元素在Canvas上的位置,通过设置其`Top`和`Left`属性。这两个属性分别定义了元素距离Canvas...
【银光+N维拼图游戏:Silverlight与WCF技术的完美融合】 本文将深入探讨一个基于Silverlight和WCF技术构建的n维拼图游戏的实现细节。Silverlight是微软推出的一种富互联网应用程序(RIA)平台,它允许开发者创建...
【Silverlight探秘系列课程(13):网络通信与开发示例】 本课程主要探讨的是Silverlight在实现网络通信及开发示例方面的知识。Silverlight是微软推出的一款跨浏览器、跨平台的插件,主要用于增强Web应用的交互性和...
2. **图形和媒体支持**:Silverlight内置了强大的图形渲染引擎,支持矢量图形、动画以及高清视频播放,使得开发富媒体应用变得轻松。 3. **跨浏览器兼容**:Silverlight插件可以在多种浏览器上运行,包括Internet ...
Silverlight 2系列(35):升级Silverlight 2 Beta 1应用程序到Beta 2 Silverlight 2系列(34):使用Silverlight Streaming托管Silverlight应用程序 Silverlight 2系列(33):Silverlight 2应用Web Service两例 ...
Silverlight 2系列(35):升级Silverlight 2 Beta 1应用程序到Beta 2 Silverlight 2系列(34):使用Silverlight Streaming托管Silverlight应用程序 Silverlight 2系列(33):Silverlight 2应用Web Service两例 ...
Silverlight是一种由微软开发的富互联网应用程序(RIA)平台,它允许开发者创建具有丰富图形、交互性和动画效果的Web应用程序。这个"Silverlight项目界面示例"提供了宝贵的资源,可以帮助你理解和模仿,以便设计出...
在本文中,我们将深入探讨如何在Silverlight应用中实现鼠标移动事件,以及如何利用这些事件让图片...通过这个实践,开发者可以更好地掌握Silverlight中的鼠标事件处理以及图形变换技术,提升动态交互界面的开发能力。
本示例“3D足球”是利用Silverlight技术实现的一个三维足球游戏或应用,展示了Silverlight在3D图形渲染和交互设计上的能力。在3D足球应用中,用户可能可以通过鼠标或键盘控制球员移动、射门、传球等操作,体验到与...
这个“silverlight 示例”压缩包很可能是为了展示Silverlight技术的应用,通过SilverlightAirlines这个示例项目来帮助开发者理解和学习Silverlight的编程。 Silverlight在2007年首次发布,作为Adobe Flash的竞争...
- Microsoft Silverlight SDK:包含开发Silverlight应用程序所需的工具和库。 - Visual Studio:用于编写、调试和部署Silverlight应用的集成开发环境(IDE)。 ### 3. 创建Silverlight项目 在Visual Studio中,...
在本文中,我们将深入探讨 Blend for Visual Studio 中的 Silverlight 示例——MagnifyingGlass(放大镜)功能。 Blend 是 Microsoft 提供的一款强大的设计工具,用于创建丰富的用户体验,特别是针对 Silverlight 和...
本示例“Silverlight用户验证”着重关注如何在Silverlight应用中实现用户输入的验证,确保数据的有效性和安全性。 在Silverlight应用中,用户验证是必不可少的一部分,它能确保用户在提交数据时遵循预设的规则,...
在Silverlight中,这通常通过操纵模型的顶点坐标或者使用特定的矩阵变换来实现。矩阵变换是图形学中的核心概念,它可以进行缩放、旋转和移动操作。对于立方体旋转,我们需要使用到旋转变换矩阵,计算每个顶点的新...