Created
September 2, 2014 09:58
-
-
Save brwnx/191c79b6c2b3befbfc7d to your computer and use it in GitHub Desktop.
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
public static boolean isDark(Bitmap bitmap){ | |
boolean dark=false; | |
float darkThreshold = bitmap.getWidth()*bitmap.getHeight()*0.45f; | |
int darkPixels=0; | |
int[] pixels = new int[bitmap.getWidth()*bitmap.getHeight()]; | |
bitmap.getPixels(pixels,0,bitmap.getWidth(),0,0,bitmap.getWidth(),bitmap.getHeight()); | |
for(int pixel : pixels){ | |
int color = pixels[i]; | |
int r = Color.red(color); | |
int g = Color.green(color); | |
int b = Color.blue(color); | |
double luminance = (0.299*r+0.0f + 0.587*g+0.0f + 0.114*b+0.0f); | |
if (luminance<150) { | |
darkPixels++; | |
} | |
} | |
if (darkPixels >= darkThreshold) { | |
dark = true; | |
} | |
long duration = System.currentTimeMillis()-s; | |
return dark; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That loop part can be optimized as-