降低Bitmap的对比度
private Bitmap reduceContrast(Bitmap bitmap, float factor) {
Bitmap result = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
paint.setFilterBitmap(true);
paint.setDither(true);
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.set(new float[]{
1 / factor, 0, 0, 0, 0,
0, 1 / factor, 0, 0, 0,
0, 0, 1 / factor, 0, 0,
0, 0, 0, 1, 0
});
paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
canvas.drawBitmap(bitmap, 0, 0, paint);
return result;
}
降低Bitmap的亮度
private Bitmap reduceBrightness(Bitmap bitmap, float factor) {
Bitmap result = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
paint.setFilterBitmap(true);
paint.setDither(true);
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.setSaturation(1 - factor);
paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
canvas.drawBitmap(bitmap, 0, 0, paint);
return result;
}