Silverlight 引路蜂二维图形库示例:多义线和多边形

jerry Silverligth 2015年11月26日 收藏

Graphics2D提供了FillPolygon ,drawPolyline来填充和绘制多边形和多义线。

  1. private void Polys()
  2. {
  3.  AffineTransform mat1;
  4.  /** Colors */
  5.  Color redColor = new Color(0x96ff0000, true);
  6.  Color greenColor = new Color(0xff00ff00, false);
  7.  Color blueColor = new Color(0x750000ff, true);
  8.  
  9.  Polyline polyline;
  10.  Polygon polygon;
  11.  Polygon polygon1;
  12.  
  13.  string pointsdata1 = "59,45,95,63,108,105,82,139,39,140,11,107,19,65";
  14.  mat1 = new AffineTransform();
  15.  mat1.Translate(130, 140);
  16.  mat1.Rotate(-30 * Math.PI / 180.0);
  17.  polyline = new Polyline();
  18.  polygon = new Polygon();
  19.  polygon1 = new Polygon();
  20.  Point[] points = Point.FromString(pointsdata1);
  21.  for (int i = 0; i < points.Length; i++)
  22.  {
  23.   polyline.AddPoint(points[i].X, points[i].Y);
  24.   polygon.AddPoint(points[i].X, points[i].Y);
  25.   polygon1.AddPoint(points[i].X, points[i].Y);
  26.  }
  27.  //Clear the canvas with white color.
  28.  graphics2D.Reset();
  29.  graphics2D.Clear(Color.White);
  30.  
  31.  graphics2D.AffineTransform = new AffineTransform();
  32.  SolidBrush brush = new SolidBrush(greenColor);
  33.  graphics2D.FillPolygon(brush, polygon);
  34.  graphics2D.AffineTransform = mat1;
  35.  brush = new SolidBrush(blueColor);
  36.  Pen pen = new Pen(redColor, 5);
  37.  graphics2D.SetPenAndBrush(pen, brush);
  38.  graphics2D.FillPolygon(null, polygon1);
  39.  graphics2D.DrawPolyline(null, polyline);
  40. }