title: How can i implement seek bar to change contrast
body: <p>I am trying to implement a seek bar to change contrast of an image in android. Anyone Help me to Implement this please.There is any other options for image processing ?
  Does anyone know the solution Please help me</p>
  
  <p>Thanks in Advance.</p>
  
  <p><strong>CODE:</strong></p>
  
  <pre><code>    public class MainActivity extends ActionBarActivity {
      ImageView imViewAndroid;
      private SeekBar seekbar;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          seekbar = (SeekBar) findViewById(R.id.seekbar);
          imViewAndroid = (ImageView) findViewById(R.id.imViewAndroid);
  
  
          seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
              @Override
              public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
  
              }
  
              @Override
              public void onStartTrackingTouch(SeekBar seekBar) {
                  imViewAndroid.setImageBitmap(takeContrast(BitmapFactory.decodeResource(getResources(), R.drawable.dicom), 100));
              }
  
              @Override
              public void onStopTrackingTouch(SeekBar seekBar) {
  
              }
          });
  
      }
    public  Bitmap takeContrast(Bitmap src, double value) {
          // src image size
          int width = src.getWidth();
          int height = src.getHeight();
          // create output bitmap with original size
          Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());
          // color information
          int A, R, G, B;
          int pixel;
          // get contrast value
          double contrast = Math.pow((100 + value) / 100, 2);
  
          // scan through all pixels
          for(int x = 0; x &lt; width; ++x) {
              for(int y = 0; y &lt; height; ++y) {
                  // get pixel color
                  pixel = src.getPixel(x, y);
                  A = Color.alpha(pixel);
                  // apply filter contrast for every channel R, G, B
                  R = Color.red(pixel);
                  R = (int)(((((R / 255.0) - 0.5) * contrast) + 0.5) * 255.0);
                  if(R &lt; 0) { R = 0; }
                  else if(R &gt; 255) { R = 255; }
  
                  G = Color.red(pixel);
                  G = (int)(((((G / 255.0) - 0.5) * contrast) + 0.5) * 255.0);
                  if(G &lt; 0) { G = 0; }
                  else if(G &gt; 255) { G = 255; }
  
                  B = Color.red(pixel);
                  B = (int)(((((B / 255.0) - 0.5) * contrast) + 0.5) * 255.0);
                  if(B &lt; 0) { B = 0; }
                  else if(B &gt; 255) { B = 255; }
  
                  // set new pixel color to output bitmap
                  bmOut.setPixel(x, y, Color.argb(A, R, G, B));
              }
          }
  
          // return final image
          return bmOut;
      }
  </code></pre>