N
Nicky
I am using Visual C# 2005 and I need help creating a filter that will
turn a picture black and white. This code I have so far is:
byte red, green, blue, avg, newColor;
int x;
int y;
ImageArray img = new ImageArray(pictureBoxMainImage.Image);
img.LockImage();
for (x = 0; x < img.Width; x++)
for (y = 0; y < img.Height; y++)
{
blue = img[x, y].B;
green = img[x, y].G;
red = img[x, y].R;
avg = (byte)((red + blue + green) / 3);
if (( red > 127) (blue > 127) (green > 127 ))
{
blue = img[255, 255].B;
green = img[255, 255].G;
red = img[255, 255].R;
//newColor = 0;
}
if ((red < 127) (blue < 127) (green < 127))
{
blue = img[0, 0].B;
green = img[0, 0].G;
red = img[0, 0].R;
//newColor = 255;
}
img[x, y] = System.Drawing.Color.FromArgb(avg, avg,
avg);
//img[x, y] = System.Drawing.Color.FromArgb(int red, int
blue, int green);
}
img.UnlockImage();
labelOutput.Text = (img.Width * img.Height).ToString();
pictureBoxMainImage.Image = img.ToBitmap();
}
Please help me with this code as I am a beginner in college and having
a terrible time.
turn a picture black and white. This code I have so far is:
byte red, green, blue, avg, newColor;
int x;
int y;
ImageArray img = new ImageArray(pictureBoxMainImage.Image);
img.LockImage();
for (x = 0; x < img.Width; x++)
for (y = 0; y < img.Height; y++)
{
blue = img[x, y].B;
green = img[x, y].G;
red = img[x, y].R;
avg = (byte)((red + blue + green) / 3);
if (( red > 127) (blue > 127) (green > 127 ))
{
blue = img[255, 255].B;
green = img[255, 255].G;
red = img[255, 255].R;
//newColor = 0;
}
if ((red < 127) (blue < 127) (green < 127))
{
blue = img[0, 0].B;
green = img[0, 0].G;
red = img[0, 0].R;
//newColor = 255;
}
img[x, y] = System.Drawing.Color.FromArgb(avg, avg,
avg);
//img[x, y] = System.Drawing.Color.FromArgb(int red, int
blue, int green);
}
img.UnlockImage();
labelOutput.Text = (img.Width * img.Height).ToString();
pictureBoxMainImage.Image = img.ToBitmap();
}
Please help me with this code as I am a beginner in college and having
a terrible time.