示例#1
0
        private void ColorList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int index = ColorList.SelectedIndex;

            if (Hexradio.IsChecked == true)
            {
                ColorsConverter converter = new ColorsConverter();
                try
                {
                    Focused().Text = converter.Tohex(FromPredColor(index));
                }
                catch (Exception)
                {
                    throw;
                }
            }
            else
            {
                try
                {
                    Focused().Text = RGBValues(FromPredColor(index));
                }
                catch (Exception)
                {
                    throw;
                }
            }

            ColorList.Visibility    = Visibility.Hidden;
            ColorPDefbtn.Background = System.Windows.Media.Brushes.Transparent;
        }
示例#2
0
 public static void TestLeoCorpLibrary()
 {
     Console.WriteLine($"The area of circle where R=10cm is {Maths.Circle.GetArea(10)}");
     Console.WriteLine($"The 55;21;125 RGB color in HEX is #{ColorsConverter.RGBtoHEX(55, 21, 125).Value}");
     Console.WriteLine($"The current Windows version is {Env.GetWindowsVersion()}");
     Console.WriteLine($"The current Unix Time is {Env.GetUnixTime()}");
 }
示例#3
0
        private void Color2Tb_TextChanged(object sender, TextChangedEventArgs e)
        {
            ColorsConverter colors = new ColorsConverter();

            if (Hexradio.IsChecked == true)
            {
                try
                {
                    Color color = colors.FromHex(Color2Tb.Text);
                    COlorLabel2.Background = new SolidColorBrush(color);
                }
                catch (Exception)
                {
                }
            }
            else if (RGBradio.IsChecked == true)
            {
                try
                {
                    int   r1    = int.Parse(Color2Tb.Text.Substring(0, Color2Tb.Text.IndexOf(",")));
                    int   b1    = int.Parse(Color2Tb.Text.Substring(Color2Tb.Text.LastIndexOf(",") + 1));
                    int   g1    = int.Parse(Color2Tb.Text.Substring(Color2Tb.Text.IndexOf(",") + 1, (Color2Tb.Text.Length - r1.ToString().Length - b1.ToString().Length - 2)));
                    Color color = colors.RGBTOColor(r1, g1, b1);
                    COlorLabel2.Background = new SolidColorBrush(color);
                }
                catch (Exception)
                {
                }
            }
            else
            {
                MessageBox.Show("Please Check one of Buttons HEX or RGB", "Option mismatch error");
            }
        }
示例#4
0
        private void ResultTb_TextChanged(object sender, TextChangedEventArgs e)
        {
            ColorsConverter colors = new ColorsConverter();

            try
            {
                Color color = colors.FromHex(ResultTb.Text);
                COlorLabel3.Background = new SolidColorBrush(color);
            }
            catch (Exception)
            {
            }
        }
示例#5
0
        public static Mat ImageToMat(Bitmap image)
        {
            var mat = new Mat(image.Width, image.Height);

            for (var x = 0; x < mat.Width; x++)
            {
                for (var y = 0; y < mat.Height; y++)
                {
                    mat.Set(x, y, ColorsConverter.RgbToGreyscale(image.GetPixel(x, y)));
                }
            }

            return(mat);
        }
示例#6
0
        private void EqualBtn_Click(object sender, RoutedEventArgs e)
        {
            ColorsConverter colors = new ColorsConverter();
            Color           color1 = new Color(), color2 = new Color();
            float           coef = 0;

            try
            {
                if (Hexradio.IsChecked == true)
                {
                    color1 = colors.FromHex(Color1Tb.Text);
                    if (Operator != '*')
                    {
                        color2 = colors.FromHex(Color2Tb.Text);
                    }
                    else
                    {
                        coef = float.Parse(Color2Tb.Text);
                    }
                }
                else if (RGBradio.IsChecked == true)
                {
                    int r1 = int.Parse(Color1Tb.Text.Substring(0, Color1Tb.Text.IndexOf(",")));
                    int b1 = int.Parse(Color1Tb.Text.Substring(Color1Tb.Text.LastIndexOf(",") + 1));
                    int g1 = int.Parse(Color1Tb.Text.Substring(Color1Tb.Text.IndexOf(",") + 1, (Color1Tb.Text.Length - r1.ToString().Length - b1.ToString().Length - 2)));
                    color1 = colors.RGBTOColor(r1, g1, b1);
                    if (Operator != '*')
                    {
                        int r2 = int.Parse(Color2Tb.Text.Substring(0, Color1Tb.Text.IndexOf(",")));
                        int b2 = int.Parse(Color2Tb.Text.Substring(Color2Tb.Text.LastIndexOf(",") + 1));
                        int g2 = int.Parse(Color2Tb.Text.Substring(Color2Tb.Text.IndexOf(",") + 1, (Color2Tb.Text.Length - r2.ToString().Length - b2.ToString().Length - 2)));

                        color2 = colors.RGBTOColor(r2, g2, b2);
                    }

                    else
                    {
                        coef = float.Parse(Color2Tb.Text);
                    }
                }
                Result        = colors.ColorOperation(color1, color2, Operator, coef);
                ResultTb.Text = Result;
                ResultColor   = colors.FromHex(Result);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message + "\nPlease enter value like #ffffff or 255,255,255");
            }
        }
示例#7
0
        public static Bitmap MatToImage(Mat img)
        {
            img.Normalize();

            var image = new Bitmap(img.Width, img.Height);

            for (var x = 0; x < image.Width; x++)
            {
                for (var y = 0; y < image.Height; y++)
                {
                    image.SetPixel(x, y, ColorsConverter.GreyscaleToRgb(img.GetAt(x, y)));
                }
            }

            return(image);
        }
示例#8
0
        private void ConvertHSL()
        {
            try
            {
                int h    = int.Parse(HTxt.Text);                                          // Parse
                int s    = int.Parse(STxt.Text);                                          // Parse
                int l    = int.Parse(LTxt.Text);                                          // Parse
                var rgb  = ColorHelper.ColorConverter.HslToRgb(new(h, (byte)s, (byte)l)); // Convert
                var hex  = ColorsConverter.RGBtoHEX(rgb.R, rgb.G, rgb.B);                 // Convert
                var hsv  = ColorHelper.ColorConverter.RgbToHsv(rgb);                      // Convert
                var cmyk = ColorHelper.ColorConverter.HslToCmyk(new(h, (byte)s, (byte)l));

                RGBTxt.Text  = $"{Properties.Resources.RGB} {rgb.R}{sep}{rgb.G}{sep}{rgb.B}";          // Set text
                HEXTxt.Text  = $"{Properties.Resources.HEX} #{(u ? hex.Value.ToUpper() : hex.Value)}"; // Set text
                HSVTxt.Text  = $"{Properties.Resources.HSV} ({hsv.H},{hsv.S},{hsv.V})";                // Set text
                HSLTxt.Text  = $"{Properties.Resources.HSL} ({h},{s},{l})";                            // Set text
                CMYKTxt.Text = $"{Properties.Resources.CMYK} {cmyk.C},{cmyk.M},{cmyk.Y},{cmyk.K}";

                hslColor  = $"({h},{s},{l})";                            // Set
                hsvColor  = $"({hsv.H},{hsv.S},{hsv.V})";                // Set
                rgbColor  = $"{rgb.R}{sep}{rgb.G}{sep}{rgb.B}";          // Set
                hexColor  = $"#{(u ? hex.Value.ToUpper() : hex.Value)}"; // Set
                cmykColor = $"{cmyk.C},{cmyk.M},{cmyk.Y},{cmyk.K}";      // Set

                ColorDisplayer.Background = new SolidColorBrush {
                    Color = Color.FromRgb(rgb.R, rgb.G, rgb.B)
                };                                                                                                              // Set color

                IconValidMsgTxt.Foreground = new SolidColorBrush {
                    Color = Color.FromRgb(0, 223, 57)
                };                                                      // Set foreground color
                IconValidMsgTxt.Text = "\uF299";                        // Set icon
                ValidMsgTxt.Text     = Properties.Resources.ColorValid; // Set text
            }
            catch
            {
                IconValidMsgTxt.Foreground = new SolidColorBrush {
                    Color = Color.FromRgb(255, 69, 0)
                };                                                        // Set foreground color
                IconValidMsgTxt.Text = "\uF36E";                          // Set icon
                ValidMsgTxt.Text     = Properties.Resources.InvalidColor; // Set text
            }
        }
示例#9
0
 private void ColorPickbtn_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         PickColorHandle pickColor = new PickColorHandle();
         pickColor.Options = ColorPickerWPF.Code.ColorPickerDialogOptions.LoadCustomPalette;
         if (Hexradio.IsChecked == true)
         {
             pickColor.PickColorButton_OnClick(Focused());
         }
         else
         {
             ColorsConverter converter = new ColorsConverter();
             pickColor.PickColorButton_OnClick(Focused());
             Focused().Text = RGBValues(converter.FromHex(Focused().Text));
         }
     }
     catch (Exception)
     {
     }
 }
示例#10
0
        private void ToCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (From == null)
            {
            }
            else
            {
                ColorsConverter converter = new ColorsConverter();
                try
                {
                    switch (ToCombo.SelectedIndex)
                    {
                    case 0:
                        ToBox.Text = converter.Tohex(From);
                        break;

                    case 1:
                        ToBox.Text = RGBValues(From);
                        break;

                    case 2:
                        Color newc = new Color();
                        newc.A     = From.A;
                        newc.R     = From.R;
                        newc.G     = From.G;
                        newc.B     = From.B;
                        ToBox.Text = newc.A.ToString() + "," + newc.R.ToString() + "," + newc.G.ToString() + "," + newc.B.ToString();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message + "\nPlease correct error and try again");
                }
            }
        }
示例#11
0
        private void ColorTxt_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (!string.IsNullOrEmpty(ColorTxt.Text))
            {
                try
                {
                    if (ColorTypeComboBox.Text == Properties.Resources.RGB)
                    {
                        string[] rgb  = ColorTxt.Text.Split(new string[] { sep }, StringSplitOptions.None);                        // Split
                        var      hsv  = ColorsConverter.RGBtoHSV(int.Parse(rgb[0]), int.Parse(rgb[1]), int.Parse(rgb[2]));         // Convert
                        var      hsl  = ColorHelper.ColorConverter.RgbToHsl(new((byte)int.Parse(rgb[0]), (byte)int.Parse(rgb[1]), (byte)int.Parse(rgb[2])));
                        var      cmyk = ColorHelper.ColorConverter.RgbToCmyk(new((byte)int.Parse(rgb[0]), (byte)int.Parse(rgb[1]), (byte)int.Parse(rgb[2])));

                        RGBTxt.Text  = $"{Properties.Resources.RGB} {rgb[0]}{sep}{rgb[1]}{sep}{rgb[2]}";                                                                                                                                                                   // Set text
                        HEXTxt.Text  = $"{Properties.Resources.HEX} #{(u ? ColorsConverter.RGBtoHEX(int.Parse(rgb[0]), int.Parse(rgb[1]), int.Parse(rgb[2])).Value.ToUpper() : ColorsConverter.RGBtoHEX(int.Parse(rgb[0]), int.Parse(rgb[1]), int.Parse(rgb[2])).Value)}"; // Set text
                        HSVTxt.Text  = $"{Properties.Resources.HSV} ({hsv.Hue},{hsv.Saturation},{hsv.Value})";                                                                                                                                                             // Set text
                        HSLTxt.Text  = $"{Properties.Resources.HSL} ({hsl.H},{hsl.S},{hsl.L})";                                                                                                                                                                            // Set text
                        CMYKTxt.Text = $"{Properties.Resources.CMYK} {cmyk.C},{cmyk.M},{cmyk.Y},{cmyk.K}";

                        rgbColor  = $"{rgb[0]}{sep}{rgb[1]}{sep}{rgb[2]}";                                                                                                                                                                             // Set text
                        hexColor  = $"#{(u ? ColorsConverter.RGBtoHEX(int.Parse(rgb[0]), int.Parse(rgb[1]), int.Parse(rgb[2])).Value.ToUpper() : ColorsConverter.RGBtoHEX(int.Parse(rgb[0]), int.Parse(rgb[1]), int.Parse(rgb[2])).Value.ToLower())}"; // Set text
                        hsvColor  = $"({hsv.Hue},{hsv.Saturation},{hsv.Value})";                                                                                                                                                                       // Set
                        hslColor  = $"({hsl.H},{hsl.S},{hsl.L})";                                                                                                                                                                                      // Set
                        cmykColor = $"{cmyk.C},{cmyk.M},{cmyk.Y},{cmyk.K}";                                                                                                                                                                            // Set
                    }
                    else if (ColorTypeComboBox.Text == Properties.Resources.HEX)
                    {
                        var    rgb  = ColorsConverter.HEXtoRGB(new() { Value = ColorTxt.Text });           // Convert
                        string hex  = ColorTxt.Text.StartsWith("#") ? ColorTxt.Text : "#" + ColorTxt.Text; // Set
                        var    hsv  = ColorsConverter.RGBtoHSV(rgb);                                       // Convert
                        var    hsl  = ColorHelper.ColorConverter.HexToHsl(new(hex));                       // Convert
                        var    cmyk = ColorHelper.ColorConverter.HexToCmyk(new(hex));

                        RGBTxt.Text  = $"{Properties.Resources.RGB} {rgb.R}{sep}{rgb.G}{sep}{rgb.B}";                  // Set text
                        HEXTxt.Text  = $"{Properties.Resources.HEX} {(u ? hex.ToUpper() : hex)}";                      // Set text
                        HSVTxt.Text  = $"{Properties.Resources.HSV} ({hsv.Hue},{hsv.Saturation},{hsv.Value})";         // Set text
                        HSLTxt.Text  = $"{Properties.Resources.HSL} ({hsl.H},{hsl.S},{hsl.L})";                        // Set text
                        CMYKTxt.Text = $"{Properties.Resources.CMYK} {cmyk.C},{cmyk.M},{cmyk.Y},{cmyk.K}";

                        rgbColor  = $"{rgb.R}{sep}{rgb.G}{sep}{rgb.B}";                  // Set text
                        hexColor  = $"{(u ? hex.ToUpper() : hex)}";                      // Set text
                        hsvColor  = $"({hsv.Hue},{hsv.Saturation},{hsv.Value})";         // Set
                        hslColor  = $"({hsl.H},{hsl.S},{hsl.L})";                        // Set
                        cmykColor = $"{cmyk.C},{cmyk.M},{cmyk.Y},{cmyk.K}";              // Set
                    }

                    string[] rC = rgbColor.Split(new string[] { sep }, StringSplitOptions.None);                     // Split
                    ColorDisplayer.Background = new SolidColorBrush {
                        Color = Color.FromRgb((byte)int.Parse(rC[0]), (byte)int.Parse(rC[1]), (byte)int.Parse(rC[2]))
                    };

                    IconValidMsgTxt.Foreground = new SolidColorBrush {
                        Color = Color.FromRgb(0, 223, 57)
                    };                                                      // Set foreground color
                    IconValidMsgTxt.Text = "\uF299";                        // Set icon
                    ValidMsgTxt.Text     = Properties.Resources.ColorValid; // Set text
                }
                catch
                {
                    IconValidMsgTxt.Foreground = new SolidColorBrush {
                        Color = Color.FromRgb(255, 69, 0)
                    };                                                        // Set foreground color
                    IconValidMsgTxt.Text = "\uF36E";                          // Set icon
                    ValidMsgTxt.Text     = Properties.Resources.InvalidColor; // Set text
                }
            }
        }
示例#12
0
        private void FromBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            string          Input     = FromBox.Text;
            ColorsConverter converter = new ColorsConverter();

            switch (FromCombo.SelectedIndex)
            {
            case 0:
            {
                try
                {
                    From = converter.FromHex(Input);
                }
                catch (Exception)
                {
                }
                break;
            }

            case 1:
            {
                try
                {
                    int r1 = int.Parse(Input.Substring(0, Input.IndexOf(",")));
                    int b1 = int.Parse(Input.Substring(Input.LastIndexOf(",") + 1));
                    int g1 = int.Parse(Input.Substring(Input.IndexOf(",") + 1, (Input.Length - r1.ToString().Length - b1.ToString().Length - 2)));
                    From = converter.RGBTOColor(r1, g1, b1);
                }
                catch (Exception)
                {
                }
                break;
            }

            case 2:
            {
                try
                {
                    int    a    = int.Parse(Input.Substring(0, Input.IndexOf(",")));
                    int    b    = int.Parse(Input.Substring(Input.LastIndexOf(",") + 1));
                    string Rest = Input.Substring(Input.IndexOf(",") + 1, Input.LastIndexOf(","));
                    int    r    = int.Parse(Rest.Substring(0, Rest.IndexOf(",")));
                    int    g    = int.Parse(Rest.Substring(Rest.IndexOf(",") + 1));
                    From = Color.FromArgb(Convert.ToByte(a), Convert.ToByte(r), Convert.ToByte(g), Convert.ToByte(b));
                }
                catch (Exception)
                {
                }
                break;
            }

            case 3:
            {
                try
                {
                    int r1 = int.Parse(Input.Substring(0, Input.IndexOf(",")));
                    int b1 = int.Parse(Input.Substring(Input.LastIndexOf(",") + 1));
                    int g1 = int.Parse(Input.Substring(Input.IndexOf(",") + 1, (Input.Length - r1.ToString().Length - b1.ToString().Length - 2)));
                    From = converter.FromHSL(r1, g1, b1);
                }
                catch (Exception)
                {
                }
                break;
            }

            case 4:
            {
                try
                {
                    int    a    = int.Parse(Input.Substring(0, Input.IndexOf(",")));
                    float  b    = float.Parse(Input.Substring(Input.LastIndexOf(",") + 1));
                    string Rest = Input.Substring(Input.IndexOf(",") + 1, Input.LastIndexOf(","));
                    float  r    = float.Parse(Rest.Substring(0, Rest.IndexOf(",")));
                    float  g    = float.Parse(Rest.Substring(Rest.IndexOf(",") + 1));

                    From = converter.FromAhsb(a, r, g, b);
                }
                catch (Exception)
                {
                }
                break;
            }
            }

            try
            {
                ConvColLabel.Background = new SolidColorBrush(From);
            }
            catch (Exception)
            {
            }
        }
示例#13
0
        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                ColorsConverter colors = new ColorsConverter();
                Color           color1 = new Color(), color2 = new Color();
                float           coef = 0;
                try
                {
                    if (Hexradio.IsChecked == true)
                    {
                        color1 = colors.FromHex(Color1Tb.Text);
                        if (Operator != '*')
                        {
                            color2 = colors.FromHex(Color2Tb.Text);
                        }
                        else
                        {
                            coef = float.Parse(Color2Tb.Text);
                        }
                    }
                    else if (RGBradio.IsChecked == true)
                    {
                        int r1 = int.Parse(Color1Tb.Text.Substring(0, Color1Tb.Text.IndexOf(",")));
                        int b1 = int.Parse(Color1Tb.Text.Substring(Color1Tb.Text.LastIndexOf(",") + 1));
                        int g1 = int.Parse(Color1Tb.Text.Substring(Color1Tb.Text.IndexOf(",") + 1, (Color1Tb.Text.Length - r1.ToString().Length - b1.ToString().Length - 2)));
                        color1 = colors.RGBTOColor(r1, g1, b1);
                        if (Operator != '*')
                        {
                            int r2 = int.Parse(Color2Tb.Text.Substring(0, Color1Tb.Text.IndexOf(",")));
                            int b2 = int.Parse(Color2Tb.Text.Substring(Color2Tb.Text.LastIndexOf(",") + 1));
                            int g2 = int.Parse(Color2Tb.Text.Substring(Color2Tb.Text.IndexOf(",") + 1, (Color2Tb.Text.Length - r2.ToString().Length - b2.ToString().Length - 2)));

                            color2 = colors.RGBTOColor(r2, g2, b2);
                        }

                        else
                        {
                            coef = float.Parse(Color2Tb.Text);
                        }
                    }
                    Result        = colors.ColorOperation(color1, color2, Operator, coef);
                    ResultTb.Text = Result;
                    ResultColor   = colors.FromHex(Result);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message + "\nPlease enter value like #ffffff or 255,255,255");
                }
            }
            else if (e.Key == Key.OemPlus || e.Key == Key.Add)
            {
                Operator           = '+';
                OperLabel.Content  = PlusBtn.Content;
                Color2Tb.Focusable = true;
                Color2Tb.Focus();
            }
            else if (e.Key == Key.OemMinus || e.Key == Key.Subtract)
            {
                Operator           = '-';
                OperLabel.Content  = MinusBtn.Content;
                Color2Tb.Focusable = true;
                Color2Tb.Focus();
            }
            else if (e.Key == Key.Multiply)
            {
                Operator           = '*';
                OperLabel.Content  = TimesBtn.Content;
                Color2Tb.Focusable = true;
                Color2Tb.Focus();
            }
            else
            {
                if (ColorList.IsVisible)
                {
                    foreach (var i in ColorList.Items)
                    {
                        if (i.ToString().Remove(0, 38).StartsWith(e.Key.ToString()))
                        {
                            ColorList.ScrollIntoView(i);
                            return;
                        }
                    }
                }
            }
        }