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

jerry Silverligth 2015年11月26日 收藏

引路蜂二维图形库中的颜色值是个32位整数,采用0xAARRGGBB格式。Alpha通道指定了颜色的透明度,0x00表示全透明,0xFF表示完全不透明。

下面的代码显示了如何创建不透明和半透明的颜色。

  1. private void Colors()
  2. {
  3.  /**
  4.    * The solid (full opaque) red color in the ARGB space
  5.    */
  6.  Color redColor = new Color(0xffff0000, false);
  7.  
  8.  /**
  9.   * The semi-opaque green color in the ARGB space (alpha is 0x78)
  10.   */
  11.  Color greenColor = new Color(0x7800ff00, true);
  12.  
  13.  /**
  14.   * The semi-opaque blue color in the ARGB space (alpha is 0x78)
  15.   */
  16.  Color blueColor = new Color(0x780000ff, true);
  17.  /**
  18.   * The semi-opaque yellow color in the ARGB space ( alpha is 0x78)
  19.   */
  20.  Color yellowColor = new Color(0x78ffff00, true);
  21.  
  22.  /**
  23.   * The dash array
  24.   */
  25.  int[] dashArray = { 20, 8 };
  26.  graphics2D.Reset();
  27.  graphics2D.Clear(Color.Black);
  28.  SolidBrush brush = new SolidBrush(redColor);
  29.  graphics2D.FillOval(brush, 30, 60, 80, 80);
  30.  brush = new SolidBrush(greenColor);
  31.  graphics2D.FillOval(brush, 60, 30, 80, 80);
  32.  Pen pen = new Pen(yellowColor, 10, Pen.CapButt, Pen.JoinMiter, dashArray, 0);
  33.  brush = new SolidBrush(blueColor);
  34.  graphics2D.SetPenAndBrush(pen, brush);
  35.  graphics2D.FillOval(null, 90, 60, 80, 80);
  36.  graphics2D.DrawOval(null, 90, 60, 80, 80);
  37. }