Android是一个用于调整位图亮度的搜索栏

时间:2012-07-26 05:36:11

标签: android image bitmap seekbar brightness

我尝试了很多代码,看过Android开发人员,但却无法使其发挥作用。我希望搜索栏调整我的位图图像亮度

3 个答案:

答案 0 :(得分:7)

查看Increase/Decrease Brightness of Image

中给出的示例

并按照下面的搜索栏进度更改进行操作

 int brightness;
 SeekBar seekbarbrightness=(SeekBar)findViewById(R.id.seekBar1);
 seekbarbrightness.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

         @Override
         public void onStopTrackingTouch(SeekBar arg0) {
          // TODO Auto-generated method stub

         }

         @Override
         public void onStartTrackingTouch(SeekBar arg0) {
          // TODO Auto-generated method stub

         }

         @Override
         public void onProgressChanged(SeekBar arg0, int progress, boolean arg2) {

             // TODO Auto-generated method stub

             brightness=progress;
             Bitmap bitmap=doBrightness(originalbitmap,brightness);
             imageView.setImageBitmap(bitmap);
         }
        });

答案 1 :(得分:1)

检查增加/减少图像亮度

时给出的示例
     int brightness;
 SeekBar seekBarBrightness=(SeekBar)findViewById(R.id.seekBar1);
 seekBarBrightness.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

     @Override
     public void onStopTrackingTouch(SeekBar arg0) {


     }

     @Override
     public void onStartTrackingTouch(SeekBar arg0) {


     }

     @Override
     public void onProgressChanged(SeekBar arg0, int progress, boolean arg2) {

       Bitmap newBitMap  =   doBrightness(bitMap,progress);

       imageView.setImageBitmap(newBitMap);

     }
    });




    public static Bitmap doBrightness(Bitmap src, int value)
    {
        // image size
        int width = src.getWidth();
        int height = src.getHeight();
        // create output bitmap
        Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());
        // color information
        int A, R, G, B;
        int pixel;

        // scan through all pixels
        for (int x = 0; x < width; ++x)
            {
                for (int y = 0; y < height; ++y)
                    {
                        // get pixel color
                        pixel = src.getPixel(x, y);
                        A = Color.alpha(pixel);
                        R = Color.red(pixel);
                        G = Color.green(pixel);
                        B = Color.blue(pixel);

                        // increase/decrease each channel
                        R += value;
                        if (R > 255)
                            {
                                R = 255;
                            } else if (R < 0)
                            {
                                R = 0;
                            }

                        G += value;
                        if (G > 255)
                            {
                                G = 255;
                            } else if (G < 0)
                            {
                                G = 0;
                            }

                        B += value;
                        if (B > 255)
                            {
                                B = 255;
                            } else if (B < 0)
                            {
                                B = 0;
                            }

                        // apply new pixel color to output bitmap
                        bmOut.setPixel(x, y, Color.argb(A, R, G, B));
                    }
            }

        // return final image
        return bmOut;
    }

答案 2 :(得分:1)

使用此示例

SeekBar sb_value = (SeekBar) findViewById(R.id.sb_value);
        final ImageView im_brightness = (ImageView) findViewById(R.id.im_brightness);
        sb_value.setProgress(125);
        sb_value.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

                im_brightness.setColorFilter(setBrightness(progress));

            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });

setBrightness方法:

public static PorterDuffColorFilter setBrightness(int progress) {
        if (progress >=    100)
        {
            int value = (int) (progress-100) * 255 / 100;

            return new PorterDuffColorFilter(Color.argb(value, 255, 255, 255), PorterDuff.Mode.SRC_OVER);

        }
        else
        {
            int value = (int) (100-progress) * 255 / 100;
            return new PorterDuffColorFilter(Color.argb(value, 0, 0, 0), PorterDuff.Mode.SRC_ATOP);


        }
    }