private void Color_Changed(object sender, RoutedEventArgs e)
        {
            colorName = ColorPicker.SelectedColorText;
            System.Windows.Media.Color tf_color = ColorPicker.SelectedColor.Value;
            string b = tf_color.ToString();

            color = System.Drawing.Color.FromArgb(tf_color.A, tf_color.R, tf_color.G, tf_color.B);
        }
 public TileColorData(System.Windows.Media.Color windowsMediaColor)
 {
     Name  = windowsMediaColor.ToString();
     Alpha = windowsMediaColor.A;
     Red   = windowsMediaColor.R;
     Green = windowsMediaColor.G;
     Blue  = windowsMediaColor.B;
     Id    = "Color-" + Alpha + "." + Red + "." + Green + "." + Blue;
 }
        public static string GetName(this System.Windows.Media.Color color)
        {
            foreach (System.Drawing.Color namedColor in GetNameLookup(color.Convert()))
            {
                try
                {
                    if ((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(namedColor.Name) == color)
                    {
                        return(namedColor.Name);
                    }
                }
                catch { }
            }

            return(color.ToString());
        }
Exemple #4
0
        /// <summary>
        /// 标准颜色转换为Rime颜色
        /// RGB转BGR
        /// </summary>
        /// <param name="color"></param>
        /// <returns></returns>
        public static string Rgb2Bgr(System.Windows.Media.Color color)
        {
            string strColor = color.ToString();

            string[] s      = strColor.Split('#');
            char[]   charss = s[1].ToCharArray();
            char[]   chars  = { charss[2], charss[3], charss[4], charss[5], charss[6], charss[7] };


            char t = chars[0];

            chars[0] = chars[4];
            chars[4] = t;

            t        = chars[1];
            chars[1] = chars[5];
            chars[5] = t;

            string returnColor = new string(chars);

            returnColor = "0x" + returnColor;
            return(returnColor);
        }
Exemple #5
0
        /// <summary>
        /// Returns a color object that represents the average colour of an image based on the settings provided.
        /// </summary>
        /// <param name="img">The image object to analyse</param>
        /// <param name="accuracy">Accuracy is determined by how many x pixels are evaluated - the lower the number, the higher the accuracy.</param>
        /// <param name="startx">X coordinate to start from.</param>
        /// <param name="starty">Y coordinate to start from.</param>
        /// <param name="endx">X coordinate to end at.</param>
        /// <param name="endy">Y coordinate to end at.</param>
        /// <returns>A color object that represents the average colour of an image based on the settings provided.</returns>
        public System.Windows.Media.Color GetAverageColour(int accuracy, int startx, int starty, int endx, int endy)
        {
            using (var bmp = new Bitmap(_image))
            {

                int width = _image.Width;
                int height = _image.Height;

                int xpc = width / 100;
                int ypc = height / 100;

                int red = 0;
                int green = 0;
                int blue = 0;
                int alpha = 0;
                int xcounter = 0;
                var ycounter = 0;

                for (int x = (startx * xpc); x < (endx * xpc)+1; x = x + accuracy)
                {
                    ycounter=0;
                    xcounter++;
                    for (int y = (starty * ypc); y < ((endy * ypc)+1); y = y + accuracy)
                    {
                        _log.Write("x=" + x + ", y=" + y);
                        ycounter++;
                        var pixel = bmp.GetPixel(x, y);
                        red += pixel.R;
                        green += pixel.G;
                        blue += pixel.B;
                        alpha += pixel.A;
                    }
                }
                Func<int, int> avg = c => c / (xcounter * ycounter);

                red = avg(red);
                green = avg(green);
                blue = avg(blue);
                alpha = avg(alpha);

                System.Windows.Media.Color color = new System.Windows.Media.Color();
                color.A = Convert.ToByte(255);
                color.R = Convert.ToByte(red);
                color.G = Convert.ToByte(green);
                color.B = Convert.ToByte(blue);
                bmp.Dispose();

                _log.Write("Detector, color: " + color.ToString());
                return color;
            }
        }
Exemple #6
0
 public static string ToRgbString(this Color argbColor) =>
 "#" + argbColor.ToString().Substring(3);
Exemple #7
0
 public override string ToString()
 {
     return(_color.ToString());
 }