c#中GraphicsPath的Warp方法

来源:互联网 发布:淘宝论文查重靠谱吗 编辑:程序博客网 时间:2024/05/14 21:48
 
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Drawing.Drawing2D;
  9. namespace advanced_drawing
  10. {
  11.     public partial class Form13 : Form
  12.     {
  13.         public Form13()
  14.         {
  15.             InitializeComponent();
  16.         }
  17.         private void Form13_Paint(object sender, PaintEventArgs e)
  18.         {
  19.             // Create a path and add a rectangle.
  20.             GraphicsPath myPath = new GraphicsPath();
  21.             RectangleF srcRect = new RectangleF(0, 0, 100, 200);
  22.             myPath.AddRectangle(srcRect);
  23.             // Draw the source path (rectangle)to the screen.
  24.             e.Graphics.DrawPath(Pens.Black, myPath);
  25.             // Create a destination for the warped rectangle.
  26.             PointF point1 = new PointF(200, 200);
  27.             PointF point2 = new PointF(400, 250);
  28.             PointF point3 = new PointF(220, 400);
  29.             PointF[] destPoints = { point1, point2, point3 };
  30.             // Create a translation matrix.
  31.             Matrix translateMatrix = new Matrix();
  32.             translateMatrix.Translate(100, 0);
  33.             // Warp the source path (rectangle).
  34.             myPath.Warp(destPoints, srcRect, translateMatrix,
  35.                 WarpMode.Perspective, 0.5f);
  36.             // Draw the warped path (rectangle) to the screen.
  37.             e.Graphics.DrawPath(new Pen(Color.Red), myPath);
  38.         }
  39.     }
  40. }
原创粉丝点击