2012-07-26 51 views

回答

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); 
     } 
     }); 
+0

TY,但它給了我這個錯誤在公共空隙「的方法類型新OnSeekBarChangeListener的onStopTrackingTouch(搜索欄)(){}必須覆蓋超類方法」,我可以通過刪除「@override」 .. – 2012-07-26 07:02:50

+0

你得到哪些錯誤修復它? – Khan 2012-07-26 07:06:42

+0

方法onProgressChanged(搜索欄,整型,布爾)型新SeekBar.OnSeekBarChangeListener(的){}必須覆蓋一個超類方法 – 2012-07-26 07:18:33

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; 
    } 
+0

這algotithm是不是在所有優化,新電話的PIC可以有超過10 MB和您實時贏得噸看到的變化 – 2015-05-25 14:46:01

+0

它工作正常。但執行更改需要很長時間。 – user123 2016-01-10 13:24:36

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); 


     } 
    }