Je développe une application dans laquelle l'utilisateur peut changer la luminosité de l'image, le contraste, la saturation, etc. Je suis capable de faire tout cela séparément en utilisant le code ci-dessous.Android Correction de la couleur de l'image. Comment changer la luminosité, la saturation, etc d'une seule image dans Android?
seekBar_brightness.setMax(512);
seekBar_brightness.setProgress(255);
seekBar_brightness.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
progress = progress - 255;
Log.e("ImageColor_bri global", "" + bitmap_global);
Bitmap new_bm = changeBrightness(bitmap_global, (float) progress);
Log.e("ImageColor_bri local", "" + new_bm);
imageView.setImageBitmap(new_bm);
bitmap_local = new_bm;
// imageView.getDrawable().setColorFilter(ColorFilterGenerator.adjustBrightness(progress));//foto is my ImageView
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
seekbar_saturation.setMax(512);
seekbar_saturation.setProgress(255);
//seekbar_saturation.setThumbOffset(255);
seekbar_saturation.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
progress = progress-255;
// imageView.buildDrawingCache();
// Bitmap bimap = imageView.getDrawingCache();
// imageView.setColorFilter(value);
Log.e("ImageColor_satu global", "" + bitmap_global);
Bitmap new_bm = adjustSaturation(bitmap_global, progress);
Log.e("ImageColor_satu local", "" + new_bm);
imageView.setImageBitmap(new_bm);
bitmap_local = new_bm;
// ColorMatrix matrix = new ColorMatrix();
// matrix.setSaturation(progress);
// ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
// imageView.getDrawable().setColorFilter(ColorFilterGenerator.adjustSaturation(progress));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
public static Bitmap changeBrightness(Bitmap bmp, float brightness) {
ColorMatrix cm = new ColorMatrix(new float[]
{
1, 0, 0, 0, brightness,
0, 1, 0, 0, brightness,
0, 0, 1, 0, brightness,
0, 0, 0, 1, 0
});
Bitmap ret = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), bmp.getConfig());
Canvas canvas = new Canvas(ret);
Paint paint = new Paint();
paint.setColorFilter(new ColorMatrixColorFilter(cm));
canvas.drawBitmap(bmp, 0, 0, paint);
return ret;
}
public static Bitmap adjustSaturation(Bitmap bmp, float value) {
value = cleanValue(value, 100);
if (value == 0) {
return bmp;
}
float x = 1 + ((value > 0) ? 3 * value/100 : value/100);
float lumR = 0.3086f;
float lumG = 0.6094f;
float lumB = 0.0820f;
float[] mat = new float[]
{
lumR * (1 - x) + x, lumG * (1 - x), lumB * (1 - x), 0, 0,
lumR * (1 - x), lumG * (1 - x) + x, lumB * (1 - x), 0, 0,
lumR * (1 - x), lumG * (1 - x), lumB * (1 - x) + x, 0, 0,
0, 0, 0, 1, 0,
0, 0, 0, 0, 1
};
ColorMatrix cm = new ColorMatrix(mat);
Bitmap ret = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), bmp.getConfig());
Canvas canvas = new Canvas(ret);
Paint paint = new Paint();
paint.setColorFilter(new ColorMatrixColorFilter(cm));
canvas.drawBitmap(bmp, 0, 0, paint);
return ret;
}
problème est la suivante: après augmentation ou diminution de la luminosité de l'image et augmenter ou diminuer la valeur de saturation change la couleur de l'image complète.
Je dois réaliser que si je inverse aux valeurs initiales de la barre de recherche de la luminosité et de la saturation je devrais obtenir l'image réelle quand c'était la première fois.
Par exemple, si augmenter la valeur de la luminosité de 0 à 100 puis modifiez la valeur de saturation de 0 à 80. Puis-je inverser la valeur de la luminosité et la saturation à 0. Ensuite, je devrais obtenir l'image originale telle qu'elle était au première fois.
Mais maintenant la couleur de l'image ne s'inverse pas en inversant sa valeur. S'il vous plaît aider. Merci d'avance.