两种方法获取图片亮度
(1)获取图片区域像素点亮度值后求平均值,该算法可以调整
public static boolean isDarkBitamp(Bitmap bitmap){
boolean isDark = false;
try {
if (bitmap != null) {
int darkPixelCount = 0;
int x = bitmap.getWidth() / 2;
int y = bitmap.getHeight() / 4;
//取图片0-width/2,竖1个像素点height/4
for (int i = 0; i < y; i++) {
if (bitmap.isRecycled()) {
break;
}
int pixelValue = bitmap.getPixel(x, i);
//取rgb值颜色
if (isDark(Color.red(pixelValue), Color.green(pixelValue), Color.blue(pixelValue))) {
darkPixelCount++;
}
}
isDark = darkPixelCount > y / 2;
Log.i("BlurScreenshotWallpaperUtil", "isDartTheme isDark " + isDark+" darkPixelCount = "+d