Silverlight 引路蜂二维图形库示例:路径

jerry Silverligth 2015年11月26日 收藏

引路蜂二维图形库也提供了对一般路径的支持,可以同过线段,二次曲线,三次曲线组成路径,也可以根据SVG指令来定义路径。

  1. private void Paths()
  2. {
  3.  AffineTransform mat1;
  4.  
  5.  /* The path.  */
  6.  Path path;
  7.  
  8.  /** Colors */
  9.  Color redColor = new Color(0x96ff0000, true);
  10.  Color greenColor = new Color(0xff00ff00, false);
  11.  Color blueColor = new Color(0x750000ff, true);
  12.  
  13.  string pathdata =
  14.     "M 60 20 Q -40 70 60 120 Q 160 70 60 20 z";
  15.  mat1 = new AffineTransform();
  16.  mat1.Translate(30, 40);
  17.  mat1.Rotate(-30 * Math.PI / 180.0);
  18.  path = Path.FromString(pathdata);
  19.  //Clear the canvas with white color.
  20.  graphics2D.Reset();
  21.  graphics2D.Clear(Color.White);
  22.  
  23.  graphics2D.AffineTransform = new AffineTransform();
  24.  SolidBrush brush = new SolidBrush(greenColor);
  25.  graphics2D.Fill(brush, path);
  26.  graphics2D.AffineTransform = mat1;
  27.  
  28.  brush = new SolidBrush(blueColor);
  29.  Pen pen = new Pen(redColor, 5);
  30.  graphics2D.SetPenAndBrush(pen, brush);
  31.  graphics2D.Draw(null, path);
  32.  graphics2D.Fill(null, path);
  33. }