ArcGIS Engine代码总结之Color 下载本文

内容发布更新时间 : 2024/12/24 2:03:56星期一 下面是文章的全部内容请认真阅读。

ArcGIS Engine代码共享-颜色(Color)对象函数

分类: ArcGIS Engine2012-01-16 14:36 2287人阅读 评论(0) 收藏 举报

classrandomlistmethodsbytenull 1. public class ColorHelper 2. {

3. // Fields

4. private static Random m_random = new Random(); 5.

6. // Methods

7. public static Color CreateColor(IColor esriColor) 8. {

9. Color black = Color.Black; 10. if (esriColor != null) 11. {

12. if (esriColor is IRgbColor) 13. {

14. IRgbColor color2 = esriColor as IRgbColor;

15. black = Color.FromArgb(color2.Red, color2.Green, color2.Blue); 16. } 17. else 18. {

19. int red = esriColor.RGB % 0x100;

20. int green = (esriColor.RGB / 0x100) % 0x100;

21. int blue = ((esriColor.RGB / 0x100) / 0x100) % 0x100; 22. black = Color.FromArgb(red, green, blue); 23. } 24. }

25. return black; 26. } 27.

28. public static IColor CreateColor(Color msColor) 29. {

30. return CreateColor(msColor.R, msColor.G, msColor.B); 31. } 32.

33. public static IColor CreateColor(int red, int green, int blue) 34. {

35. RgbColorClass class2 = new RgbColorClass(); 36. class2.Red = red; 37. class2.Green = green; 38. class2.Blue = blue; 39. return class2;

40. } 41.

42. public static IColor CreateColor(byte alpha, int red, int green, int blue) 43. {

44. RgbColorClass class2 = new RgbColorClass(); 45. class2.Red = red; 46. class2.Green = green; 47. class2.Blue = blue;

48. class2.Transparency = alpha; 49. return class2; 50. } 51.

52. public static IColor CreateRandomColor() 53. {

54. return CreateRandomColor(100); 55. } 56.

57. public static IColor CreateRandomColor(byte alpha) 58. {

59. int red = m_random.Next(0xff); 60. int green = m_random.Next(0xff); 61. int blue = m_random.Next(0xff);

62. return CreateColor(alpha, red, green, blue); 63. } 64.

65. public static List CreateRandomColorList(int pCount) 66. {

67. List list = new List(); 68. List list2 = new List(); 69. while (list.Count < pCount) 70. {

71. Color item = CreateRandomMSColor(); 72. if (!list.Contains(item)) 73. {

74. list.Add(item); 75. } 76. }

77. foreach (Color color2 in list) 78. {

79. list2.Add(CreateColor(color2)); 80. }

81. return list2; 82. } 83.

84. public static Color CreateRandomMSColor() 85. {

86. int red = m_random.Next(0xff); 87. int green = m_random.Next(0xff); 88. int blue = m_random.Next(0xff);

89. return Color.FromArgb(red, green, blue); 90. } 91. }