How to find that all pixels in an image are grey scale or has R,G,B equal value for each individual pixel

前端 未结 2 755
情深已故
情深已故 2021-01-16 18:17

Please dont quote this How can I check the color depth of a Bitmap? or How to check if a picture is in grayScale

Because an image can be 24/32 bit per pixel even if

2条回答
  •  礼貌的吻别
    2021-01-16 19:05

    Ok you need to take the RGB components of a bit sequence. Lets say the sequence is 24 bits so you have the following bit sequence:

    RRRRRRRRGGGGGGGGBBBBBBBB
    

    WhereR is a bit for red, G is a bit for green and B is a bit for blue. To separate this you can do it with bitwise operators.

    color = Bitmap.GetPixel(iCounter, iCount).ToArgb();
    blue  = color & 0xFF;          // Get the 1st 8 bits
    green = (color >> 8)  & 0xFF;  // Remove the 1st 8 bits and take the 2n 8 bits
    red   = (color >> 16) & 0xFF;  // Remove the 1st 16 bits and take the 3rd 8 bits
    

提交回复
热议问题