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

前端 未结 2 757
情深已故
情深已故 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 18:51

    Bitmap.GetPixel() returns a Color structure which has fields R, G and B so you can just compare them however you want.

    Do note that using GetPixel() is very slow, but if you don't need speed it will do.

    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题