System.OverflowException: Value was either too large or too small for an Int32 - C#

Узнай цену своей работы

Формулировка задачи:

private void button5_Click(object sender, EventArgs e)
        {
            New.img5 = new Bitmap(New.NAME_FILE);
            Color f;
            for (int i = 0; i < New.img5.Height; i++)
                for (int j = 0; j < New.img5.Width; j++)
                {
                    f = New.img5.GetPixel(j, i);
                    if (f.G >= f.B)
                    {
                        double h = (1 / (2 * 3.14)) * (3.14 / 2 - Math.Atan((2 * f.R - f.G - f.B) / (Math.Sqrt(3) * (f.G - f.B))));
                        double s1 = Math.Sqrt(f.R * f.R + f.G * f.G + f.B * f.B - f.R * f.G - f.R * f.B - f.B * f.G);
                        double l1 = (f.R + f.G + f.B) / 3;
                        f = Color.FromArgb(Convert.ToByte(h), Convert.ToByte(s1), Convert.ToByte(l1));
                        New.img5.SetPixel(j, i, f);
                    }
                    else
                    {
                        double h = (1 / (2 * 3.14)) * ((3.14 * 3 / 2 - Math.Atan((2 * f.R - f.G - f.B) / (Math.Sqrt(3) * (f.G - f.B)))));
                        double s1 = Math.Sqrt(f.R * f.R + f.G * f.G + f.B * f.B - f.R * f.G - f.R * f.B - f.B * f.G);
                        double l1 = (f.R + f.G + f.B) / 3;
                        f = Color.FromArgb(Convert.ToByte(h), Convert.ToByte(s1), Convert.ToByte(l1));
                        New.img5.SetPixel(j, i, f);
                    }
                }
            pictureBox2.Image = New.img5;
            pictureBox2.SizeMode = PictureBoxSizeMode.Zoom;
 
        }
Ошибка в строчке
f = Color.FromArgb(Convert.ToByte(h), Convert.ToByte(s1), Convert.ToByte(l1));
Как это можно исправить?

Решение задачи: «System.OverflowException: Value was either too large or too small for an Int32»

textual
Листинг программы
...(f.G - f.B)))); // при f.G = f.B, выражение равно 0, и потом происходило деление на 0.

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

12   голосов , оценка 3.833 из 5
Похожие ответы