title: Replace specific color in bitmap with transparency
body: <p>I have a method to replace a pixel of one color with transparency</p>
  
  <pre><code>public Bitmap createTransparentBitmapFromBitmap(Bitmap bitmap,
            int replaceThisColor) {
          if (bitmap != null) {
            int picw = bitmap.getWidth(); 
            int pich = bitmap.getHeight();
            int[] pix = new int[picw * pich];
            bitmap.getPixels(pix, 0, picw, 0, 0, picw, pich);
  
            int sr = (replaceThisColor &gt;&gt; 16) &amp; 0xff;
            int sg = (replaceThisColor &gt;&gt; 8) &amp; 0xff;
            int sb = replaceThisColor &amp; 0xff;
  
            for (int y = 0; y &lt; pich; y++) {   
              for (int x = 0; x &lt; picw; x++) {
                int index = y * picw + x;
              /*  int r = (pix[index] &gt;&gt; 16) &amp; 0xff;
                int g = (pix[index] &gt;&gt; 8) &amp; 0xff;
                int b = pix[index] &amp; 0xff;*/
  
                if (pix[index] == replaceThisColor) {
  
                  if(x&lt;topLeftHole.x) topLeftHole.x = x;  
                  if(y&lt;topLeftHole.y) topLeftHole.y = y;
                  if(x&gt;bottomRightHole.x) bottomRightHole.x = x;
                  if(y&gt;bottomRightHole.y)bottomRightHole.y = y;
  
                  pix[index] = Color.TRANSPARENT;   
                } else {
                  //break;
                }
              }
            }
  
            Bitmap bm = Bitmap.createBitmap(pix, picw, pich,
                Bitmap.Config.ARGB_8888);  
  
            return bm;
          }
          return null;
        }
  </code></pre>
  
  <p>Its called like this</p>
  
  <pre><code>backgroundBitmap = createTransparentBitmapFromBitmap(backgroundBitmap , Color.argb(255,255,255, 0));
  </code></pre>
  
  <p>The same color i have in a png file, where i want the transparent hole.The problem is it only replaces part of the color not all.
  See screenshot <a href="https://docs.google.com/document/d/18aH43sFmsuuRu0QNfMTD1zek8sqWwH_pTauFofDZeIw/edit" rel="nofollow">https://docs.google.com/document/d/18aH43sFmsuuRu0QNfMTD1zek8sqWwH_pTauFofDZeIw/edit</a></p>