Last active
September 12, 2016 16:46
-
-
Save daverix/6f539826e558ad3c135ba647ac20ef37 to your computer and use it in GitHub Desktop.
calculate color from pixel buffer in RGBX_8888 mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final int limit = buffer.limit(); | |
final int pixels = limit / 4; | |
long red = 0; | |
long green = 0; | |
long blue = 0; | |
for(int i=0;i<limit;i+=4) { | |
int color = buffer.getInt(i); | |
red += 0xFF & color; | |
green += 0x00FF & (color >> 8); | |
blue += 0x0000FF & (color >> 16); | |
} | |
int avgRed = (int) (red / pixels); | |
int avgGreen = (int)(green / pixels); | |
int avgBlue = (int) (blue / pixels); | |
Log.d("BLS", String.format(Locale.ENGLISH, "0x%s", | |
Integer.toHexString(avgRed << 16 | avgGreen << 8 | avgBlue))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment