您的位置:首页 > 编程语言

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

2012-01-16 14:36 417 查看
public class ColorHelper
    {
        // Fields
        private static Random m_random = new Random();

        // Methods
        public static Color CreateColor(IColor esriColor)
        {
            Color black = Color.Black;
            if (esriColor != null)
            {
                if (esriColor is IRgbColor)
                {
                    IRgbColor color2 = esriColor as IRgbColor;
                    black = Color.FromArgb(color2.Red, color2.Green, color2.Blue);
                }
                else
                {
                    int red = esriColor.RGB % 0x100;
                    int green = (esriColor.RGB / 0x100) % 0x100;
                    int blue = ((esriColor.RGB / 0x100) / 0x100) % 0x100;
                    black = Color.FromArgb(red, green, blue);
                }
            }
            return black;
        }

        public static IColor CreateColor(Color msColor)
        {
            return CreateColor(msColor.R, msColor.G, msColor.B);
        }

        public static IColor CreateColor(int red, int green, int blue)
        {
            RgbColorClass class2 = new RgbColorClass();
            class2.Red = red;
            class2.Green = green;
            class2.Blue = blue;
            return class2;
        }

        public static IColor CreateColor(byte alpha, int red, int green, int blue)
        {
            RgbColorClass class2 = new RgbColorClass();
            class2.Red = red;
            class2.Green = green;
            class2.Blue = blue;
            class2.Transparency = alpha;
            return class2;
        }

        public static IColor CreateRandomColor()
        {
            return CreateRandomColor(100);
        }

        public static IColor CreateRandomColor(byte alpha)
        {
            int red = m_random.Next(0xff);
            int green = m_random.Next(0xff);
            int blue = m_random.Next(0xff);
            return CreateColor(alpha, red, green, blue);
        }

        public static List<IColor> CreateRandomColorList(int pCount)
        {
            List<Color> list = new List<Color>();
            List<IColor> list2 = new List<IColor>();
            while (list.Count < pCount)
            {
                Color item = CreateRandomMSColor();
                if (!list.Contains(item))
                {
                    list.Add(item);
                }
            }
            foreach (Color color2 in list)
            {
                list2.Add(CreateColor(color2));
            }
            return list2;
        }

        public static Color CreateRandomMSColor()
        {
            int red = m_random.Next(0xff);
            int green = m_random.Next(0xff);
            int blue = m_random.Next(0xff);
            return Color.FromArgb(red, green, blue);
        }
    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: