Enhancing ImageView brightness programmatically

前端 未结 5 1950
不知归路
不知归路 2021-01-03 10:56

I have an android app in which I am increasing brightness of image with the code below. But this is very slow so does anyone knows a fast way to enhance image brightness of

5条回答
  •  孤街浪徒
    2021-01-03 11:19

    The above answers didnt work for me as I had an imageview with image set using bitmap. So this is what it worked:

        private ColorMatrixColorFilter brightness(float value) {
            ColorMatrix cmB = new ColorMatrix();
            cmB.set(new float[]{
                    1, 0, 0, 0, value,
                    0, 1, 0, 0, value,
                    0, 0, 1, 0, value,
                    0, 0, 0, 1, 0});
            return new ColorMatrixColorFilter(cmB);
        }
    

    Have a seek bar with controls the brightness.Its range is from -255 to 255.

     sbBrightness.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    if(fromUser){
                        photoFilterView.getSource().setColorFilter(brightness(progress));
    
                   /*     Filter brightness=new Filter();
                        brightness.addSubFilter(new BrightnessSubFilter(progress));
    
                        Bitmap ouputImage = brightness.processFilter(bm);
                        photoFilterView.getSource().setImageBitmap(ouputImage);*/
                    }
                }
    
                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
    
                }
    
                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            sbBrightness.setVisibility(View.GONE);
                        }
                    },1000);
    
                }
            });
    

    Hope it helps some.

提交回复
热议问题