Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement