___89___GraphicsPath_GDI矩阵变幻Transform
来源:互联网 发布:linux开发语言 编辑:程序博客网 时间:2024/05/16 12:33
#region Windows Form Designer generated code/// <summary>/// Required method for Designer support - do not modify/// the contents of this method with the code editor./// </summary> private void InitializeComponent(){ // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(392, 170); this.Name = "Form1"; this.Text = "Transform"; }#endregion/// <summary>/// The main entry point for the application./// </summary>[STAThread]static void Main() {Application.Run(new Form1());} protected override void OnPaint(PaintEventArgs pe) { const float offsetValue = 80.0f; // used to translate the diagram //Graphics类,封装一个 GDI+ 绘图图面。此类不能被继承 Graphics g = pe.Graphics ; //矩形,一个矩形的有位置和大小信息 Rectangle rect = this.ClientRectangle; //LinearGradientBrush 使用线性渐变封装 Brush。此类不能被继承。 LinearGradientBrush lBrush = new LinearGradientBrush(rect, Color.Yellow, Color.Lime, LinearGradientMode.BackwardDiagonal); g.FillRectangle(lBrush, rect); // create a graphics path GraphicsPath gp = new GraphicsPath(); /* GraphicsPath对象 它由一系列相互连接的直线、曲线连接起来组成的开放(非闭合)图形。 创建路径时就会隐式创建一个新图形(由上面的直线、曲线等组成)。也可以 显示地声明StartFigure。 */ // 在当前图形中添加一段立方贝塞尔曲线 gp.AddBezier(110, 110, 110, 115, 120, 115, 125, 130); // 向当前路径添加一个椭圆 gp.AddEllipse(125,130, 8,8); // save a copy of the graphics path so we can reset // each time we rotate it. GraphicsPath gpOld = new GraphicsPath(); gpOld = (GraphicsPath)gp.Clone(); //Clone方法获得路径对象的指针 // offset path Matrix--C#矩阵类--封装表示几何变换的 3x3 仿射矩阵 Matrix aTransform = new Matrix(1, 0, 0, 1, 0, 0); Matrix TranslationTransform = new Matrix(1, 0, 0, 1, 0, 0); // PointF 表示在二维平面中定义点的浮点 x 和 y 坐标的有序对 PointF TheRotationPoint = new PointF(110.0f, 110.0f); // cycle through 4 translated balloon wheel patterns for (int i = 0; i < 4; i++) { // cycle through 360 degrees and draw a balloon at each 45 degree angle for (float f = 0.0f; f < 359.0; f += (float)45.0) { // use the translation matrix to translate the graphics path // to the right 将变换矩阵-TranslationTransform-应用到此 GraphicsPath。 gp.Transform(TranslationTransform); // rotate the rotation transformation matrix f degrees around TheRotationPoint //沿 point 参数中指定的点-TheRotationPoint-并通过预先计算该旋转f(45度),来顺时针旋转此 Matrix aTransform.RotateAt(f, TheRotationPoint); //Call the Transform method of the Graphics Path in order to multiply it by the rotation matrix and rotate the balloon //将变换矩阵-aTransform-应用到此 GraphicsPath。 gp.Transform(aTransform); // Fill the balloon with a red colored brush //填充 GraphicsPath 的内部 g.FillPath(Brushes.Red, gp); // Draw the balloon with a black pen //绘制 GraphicsPath。 g.DrawPath(Pens.Black, gp); // reset the transformation matrix aTransform.Dispose(); aTransform = new Matrix(1, 0, 0, 1, 0, 0); // get the original graphics path for our rotation and translation reference gp = (GraphicsPath)gpOld.Clone(); } //move the translation matrix by an offset. When the matrix is then // used in the transform method(above), it causes the balloon wheel to // be drawn to the right (translation in the positive X direction) //通过预先计算转换向量,将指定的转换向量(offsetX 和 offsetY)应用到此 Matrix TranslationTransform.Translate(offsetValue, 0); // We also need to translate the point that we rotate around TheRotationPoint.X = TheRotationPoint.X + offsetValue; } g.DrawString("Translations and Rotation Transforms in GDI+", new Font("Times New Roman", 14), Brushes.DarkBlue, 20, 20, new StringFormat()); }
运行效果
0 0
- ___89___GraphicsPath_GDI矩阵变幻Transform
- 变幻的矩阵
- 变幻的矩阵
- 变幻的矩阵
- 12:变幻的矩阵
- 变幻的矩阵
- 12:变幻的矩阵
- 12_变幻的矩阵
- OpenJudge noi 12变幻的矩阵
- 2015年国家集训队测试 BZOJ3816矩阵变幻
- CSS3 transform中的Matrix(矩阵)
- 矩阵matrix和transform-origin
- Noi题库 矩阵归零消减序列和&&变幻的矩阵
- Unity手游之路<四>3d旋转-四元数,欧拉角和变幻矩阵
- Unity手游之路<四>3d旋转-四元数,欧拉角和变幻矩阵
- Unity手游之路<四>3d旋转-四元数,欧拉角和变幻矩阵
- Unity手游之路<四>3d旋转-四元数,欧拉角和变幻矩阵
- Android图片平移缩放(一):Matrix矩阵变幻:Scale, Translation,Skew
- Qt核心剖析:信息隐藏
- 【IOS自定义工具类之缓存助手类】CacheHelper
- 2015百度招聘
- 解决pip无法使用http的源
- jsp相关知识
- ___89___GraphicsPath_GDI矩阵变幻Transform
- 乍得“随军”记 ——写在结婚一周年
- CentOS/RedHat和Ubuntu/Debian彻底修改主机名(hostname)的方法
- 关于iOS中图片的平铺
- 【精】配色达人速成
- jenkins 构建触发器 区别
- 【python 笔记】字符串translate用法
- 对象归档
- AFNetworking 中 设置 https的SSL认证