title: Android color splash
body: <p>Can someone suggest me a fast method or a library for color splash effect? For example, I select a color and a photo gets desaturated for all colors except that one I have picked.</p>
  
  <p>I have tried using pixel by pixel color check and then replace the color but it is too slow for big images.</p>
  
  <pre><code>int width = originalImage.getWidth();
  int height = originalImage.getHeight();
  int[] pixels = new int[width * height];
  originalImage.getPixels(pixels, 0, width, 0, 0, width, height);
  
  for (int x = 0; x &lt; pixels.length; ++x) {
       pixels[x] = Distance(pixels[x], fromColor) &lt; 4 ? targetColor : pixels[x];
  }
  
  Bitmap newImage = Bitmap.createBitmap(width, height, originalImage.getConfig());
  newImage.setPixels(pixels, 0, width, 0, 0, width, height);
  
  
  public int Distance(int a, int b) {
       return Math.abs(Color.red(a) - Color.red(b)) + Math.abs(Color.green(a) -
                       Color.green(b)) + Math.abs(Color.blue(a) - Color.blue(b));
  }
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Here are the original and the processed images, the color I am keeping is #ff9350:
  <a href="https://i.stack.imgur.com/8JMuJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8JMuJ.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/UhAT1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UhAT1.png" alt="enter image description here"></a></p>