1) First determine the dimension of the image,
2) loop through each pixel and check whether any color other than white or black exist , if yes, echo "color image" message.
Code snippet:
static int check;
protected void Page_Load(object sender, EventArgs e)
{
int x,y;
Bitmap image = (Bitmap) Bitmap.FromFile(@"C:\xyz\test_color.bmp");
x = Int32.Parse(image.Width.ToString());
y = Int32.Parse(image.Height.ToString());
for(int i =0;i<x;i++)
{
for (int j = 0; j < y; j++)
{
Color pixelColor = image.GetPixel(i, j);
if ( (pixelColor.R == 255 && pixelColor.G == 255 && pixelColor.B == 255) || (pixelColor.R == 0 && pixelColor.G == 0 && pixelColor.B == 0))
continue;
else
{
check = -1;
lblUserName.Text = "Color Image";
break;
}
}
if (check < 0)
break;
}
Sukesh.net, if this helps please login to Mark As Answer. | Alert Moderator