Beispiel #1
0
        public Image ToImage(int[,] img, ColorPart part)
        {
            var bmp = new Bitmap(img.GetLength(0), img.GetLength(1));

            for (var y = 0; y < bmp.Height; y++)
            {
                for (var x = 0; x < bmp.Width; x++)
                {
                    switch (part)
                    {
                    case ColorPart.Red:
                        bmp.SetPixel(x, y, Color.FromArgb(img[x, y], 0, 0));
                        break;

                    case ColorPart.Green:
                        bmp.SetPixel(x, y, Color.FromArgb(0, img[x, y], 0));
                        break;

                    case ColorPart.Blue:
                        bmp.SetPixel(x, y, Color.FromArgb(0, 0, img[x, y]));
                        break;

                    case ColorPart.Gray:
                        var value = img[x, y];
                        bmp.SetPixel(x, y, Color.FromArgb(value, value, value));
                        break;
                    }
                }
            }
            return(bmp);
        }
Beispiel #2
0
        public int[,] ToByte(Image img, ColorPart part)
        {
            var bmp  = new Bitmap(img);
            var mass = new int[bmp.Width, bmp.Height];

            for (var y = 0; y < img.Height; y++)
            {
                for (var x = 0; x < img.Width; x++)
                {
                    switch (part)
                    {
                    case ColorPart.Red:
                        mass[x, y] = bmp.GetPixel(x, y).R;
                        break;

                    case ColorPart.Green:
                        mass[x, y] = bmp.GetPixel(x, y).G;
                        break;

                    case ColorPart.Blue:
                        mass[x, y] = bmp.GetPixel(x, y).B;
                        break;

                    case ColorPart.Gray:
                        mass[x, y] = (bmp.GetPixel(x, y).R + bmp.GetPixel(x, y).G + bmp.GetPixel(x, y).B) / 3;
                        break;
                    }
                }
            }
            return(mass);
        }
Beispiel #3
0
        private void OnValueChanged(string newValue, ColorPart colorPart)
        {
            if (ConfigField == null)
            {
                return;
            }
            if (!int.TryParse(newValue, out var number))
            {
                return;
            }

            switch (colorPart)
            {
            case ColorPart.R:
                if (ProcessColorPart(number, colorR))
                {
                    return;
                }
                currentColor.r = (byte)number;
                break;

            case ColorPart.G:
                if (ProcessColorPart(number, colorG))
                {
                    return;
                }
                currentColor.g = (byte)number;
                break;

            case ColorPart.B:
                if (ProcessColorPart(number, colorB))
                {
                    return;
                }
                currentColor.b = (byte)number;
                break;

            case ColorPart.A:
                if (ProcessColorPart(number, colorA))
                {
                    return;
                }
                currentColor.a = (byte)number;
                break;
            }

            preview.color = currentColor;

            ConfigField.OnValueChanged(new Color(currentColor.r, currentColor.g, currentColor.b, currentColor.a));
        }
Beispiel #4
0
        private string GetColor(string rgb, ColorPart color)
        {
            rgb = rgb.Replace(",", "");
            switch (color)
            {
            case ColorPart.A:
                return(rgb.Remove(2, rgb.Length - 2));

            case ColorPart.R:
                return(rgb.Substring(2, 2));

            case ColorPart.G:
                return(rgb.Substring(4, 2));

            default:
                return(rgb.Substring(6));
            }
        }
Beispiel #5
0
        public TimeSelectControl()
        {
            InitializeComponent();

            for (int i = 1; i <= 5; i++)
            {
                for (int j = 1; j <= 10; j++)
                {
                    ColorPart colpart = new ColorPart();
                    Grid.SetColumn(colpart, i);
                    Grid.SetRow(colpart, j);
                    colpart.stC = i;
                    colpart.stR = j;
                    timetable.Children.Add(colpart);
                    map[i, j] = colpart;
                }
                ;
            }
        }
Beispiel #6
0
        private void OnEndEdit(string newValue, ColorPart colorPart)
        {
            if (ConfigField == null)
            {
                return;
            }
            if (!int.TryParse(newValue, out var number))
            {
                var isEmpty = string.IsNullOrEmpty(newValue);
                switch (colorPart)
                {
                case ColorPart.R:
                    colorR.text = isEmpty ? "0" : currentColor.r.ToString();
                    break;

                case ColorPart.G:
                    colorG.text = isEmpty ? "0" : currentColor.g.ToString();
                    break;

                case ColorPart.B:
                    colorB.text = isEmpty ? "0" : currentColor.b.ToString();
                    break;

                case ColorPart.A:
                    colorA.text = isEmpty ? "0" : currentColor.a.ToString();
                    break;
                }
            }
            var currentValue = ConfigField.GetValue();

            if (currentValue == currentColor)
            {
                return;
            }
            ConfigField.OnEndEdit(new Color(currentColor.r, currentColor.g, currentColor.b, currentColor.a));
        }
 private string GetColor(string rgb, ColorPart color)
 {
     rgb = rgb.Replace(",", "");
     switch (color)
     {
         case ColorPart.A:
             return rgb.Remove(2, rgb.Length-2);
         case ColorPart.R:
             return rgb.Substring(2, 2);
         case ColorPart.G:
             return rgb.Substring(4, 2);
         default:
             return rgb.Substring(6);
     }
 }