2

I want to set Brightness of an image on SeekBar OnProgres change event? I am showing an image in imageview and below that there is an SeekBar to change the Brightness of an image.

1) I am using following function to set brightness

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) I was able to set brightness of an image using following code

@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) Now I want to change the brightness of an image on SeekBar OnProgress change event, but for that I require to have an relationship between ColorMatrix and Bitmap.

Because I don't want to draw an image I want to modify an existing image. i.e. I am showing an image in imageview and below that there is an SeekBar to change the Brightness of an image.

Please help me to change the Brightness of an image onSeekBar Progressed change event.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
PCS
  • 211
  • 3
  • 11

1 Answers1

0

First of all u need to make the colormatrix cm method variable as a instance variable change the value of the contrast using the OnSeekBarChangeListener into the colormatrix and redraw the entire view

u.jegan
  • 833
  • 6
  • 15
  • thanks for your answer but still i am not yet understand. 1)How can i redraw the entire view.? 2)Is it possible redraw entire view on SeekBar.setOnSeekBarChangeListener onProgressChanged event.? – PCS May 19 '11 at 08:38
  • @PCS yes it is possible to redraw view using the seekbarchange u should call the invaliadte method to redraw and use a runnable to invalidate – u.jegan May 20 '11 at 07:55