Bitwise version of finding RGB in java
问题 I have the following method that gets a rgb value and classifies it using a smaller palette: private static int roundToNearestColor( int rgb, int nrColors ) { int red = ( rgb >> 16 ) & 0xFF; int green = ( rgb >> 8 ) & 0xFF; int blue = ( rgb & 0xFF ); red = red - ( red % nrColors ); green = green - ( green % nrColors ); blue = blue - ( blue % nrColors ); return 0xFF000000 | ( red << 16 ) | ( green << 8 ) | ( blue ); } The code that annoys me is red = red - ( red % nrColors ); green = green - (