2009년 12월 7일 월요일

[ArcObjects]IColor

ArcObjects에서 IColor를 생성하기 위한 몇가지 예제입니다.
 - System.Drawing.Color
 - Red, Green, Blue


[code c#]
public static class ColorFactory
{
  public static IColor ToColor(System.Drawing.Color color)
  {
      IRgbColor ipRgbColor = new RgbColorClass();

      ipRgbColor.RGB = System.Drawing.ColorTranslator.ToWin32(color);

      if (color == System.Drawing.Color.Transparent) ipRgbColor.NullColor = true;

      ipRgbColor.UseWindowsDithering = true;

      return ipRgbColor;
  }

  public static IColor ToColor(int red, int green, int blue)
  {
      IRgbColor ipRgbColor = new RgbColorClass();

      ipRgbColor.Red = red;
      ipRgbColor.Green = green;
      ipRgbColor.Blue = blue;

      ipRgbColor.UseWindowsDithering = true;

      return ipRgbColor;
  }

  public static IColor ToColor(int RGB)
  {
      IRgbColor ipRgbColor = new RgbColorClass();

      //RGB = Long (ASCII) number calculated from the Red, Green and Blue color attributes.
      ipRgbColor.RGB = RGB;
      ipRgbColor.UseWindowsDithering = true;

      return ipRgbColor;
  }

  public static IColor RandomColor
  {
      get
      {
          System.Random rnd = new System.Random();
          return ToColor(rnd.Next(255), rnd.Next(255), rnd.Next(255));
      }
  }
}
[/code]

댓글 없음:

댓글 쓰기