[英]I want to set Brightness of an image on SeekBar OnProgres change event in Android?
我想在SeekBar OnProgres更改事件上設置圖像的亮度嗎? 我在imageview中顯示一個圖像,下面有一個SeekBar來更改圖像的亮度。
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更改事件中更改圖像的亮度。
首先,您需要使用OnSeekBarChangeListener將colormatrix cm方法變量作為實例變量,將對比度值更改為colormatrix並重繪整個視圖
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.