SeekBar OnProgres 変更イベントで画像の明るさを設定したいですか? 画像の明るさを変更するための SeekBar があることの下に、imageview に画像を表示しています。
1)次の関数を使用して明るさを設定しています
private static void setBrightness(ColorMatrix cm, float contrast) {
float scale = contrast + 1.f;
float translate = (-.5f * scale + .5f) * 255.f;
cm.set(new float[] {
1, 0, 0, 0, translate,
0, 1, 0, 0, translate,
0, 0, 1, 0, translate,
0, 0, 0, 1, 0 });
}
2)次のコードを使用して画像の明るさを設定できました
@Override protected void onDraw(Canvas canvas) {
Paint paint = mPaint;
float x = 20;
float y = 20;
float[]pos={5,5};
canvas.drawColor(Color.WHITE);
paint.setColorFilter(null);
canvas.drawText("Original Image", 5,20, paint);
canvas.drawBitmap(mBitmap, x, y, paint);
ColorMatrix cm = new ColorMatrix();
mAngle += 2;
if (mAngle > 180) {
mAngle = 0;
}
//convert our animated angle [-180...180] to a contrast value of [-1..1]
float contrast = mAngle / 180.f;
canvas.drawText("Brightness", 5,y + 60, paint);
setBrightness(cm, contrast);//Brightness
paint.setColorFilter(new ColorMatrixColorFilter(cm));
canvas.drawBitmap(mBitmap, x ,y + mBitmap.getWidth() + 10, paint);
invalidate();
}
3) SeekBar OnProgress 変更イベントで画像の明るさを変更したいのですが、そのためには ColorMatrix と Bitmap の間に関係が必要です。
画像を描きたくないので、既存の画像を変更したい。つまり、imageview で画像を表示しています。その下には、画像の明るさを変更するための SeekBar があります。
画像 onSeekBar Progressed 変更イベントの明るさを変更するのを手伝ってください。