Witam serdecznie,
Z niewiadomego mi powodu dostaję błąd kompilatora o treści "Use of an unassigned variable 'H' " w linijce if (H < 0)
Byłbym ogromnie wdzięczny gdyby ktoś rzucił na to okiem i podsunął jakiś pomysł na rozwiązanie tego problemu.
Pozdrawiam.
<code class="c#">
private void button6_Click(object sender, EventArgs e)
{
Bitmap image = (Bitmap)pictureBox1.Image;
Bitmap preview = new Bitmap(image);
for (int i = 0; i < image.Width; i++)
{
for (int j = 0; j < image.Height; j++)
{
Color a = image.GetPixel(i, j);
a = Color.FromArgb(a.R, a.B, a.G);
float hue = a.GetHue();
float saturation = a.GetSaturation();
float lightness = a.GetBrightness();
float red = (float)a.R/255;
float green = (float)a.G / 255; ;
float blue = (float)a.B / 255; ;
int min=Math.Min(Math.Min((int)red,(int)green),(int)blue);
int max=Math.Max(Math.Max((int)red,(int)green),(int)blue);
int delta = max - min;
float H, S;
float L = (max + min) / 2;
if (delta == 0)
{
H = 0;
S = 0;
}
else
{
if(L<0.5)
{
S = delta / (max + min);
}
else
{
S = delta / (2 - max - min);
}
float deltaRed = (((max - red) / 6) + (max / 2)) / max;
float deltaGreen = (((max - green) / 6) + (max / 2)) / max;
float deltaBlue = (((max - blue) / 6) + (max / 2)) / max;
if (red == max)
{
H = deltaBlue - deltaGreen;
}
else if (green == max)
{
H = (1 / 3) + deltaGreen - deltaBlue;
}
else if (blue == max)
{
H = (2 / 3) + deltaGreen - deltaRed;
}
if (H < 0)
{
H += 1;
}
if (H > 1)
{
H -= 1;
}
}
int r = (int)H;
int g = (int)S;
int b = (int)L;
Color q=Color.FromArgb(r,g,b);
preview.SetPixel(i, j, q);
}
}
pictureBox2.Image = preview;
}