Very good, I needed it, and then I improved a bit, the code:
public static Bitmap repleceIntervalColor(Bitmap bitmap,int redStart,int redEnd,int greenStart, int greenEnd,int blueStart, int blueEnd,int colorNew) { 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); for (int y = 0; y < pich; y++) { for (int x = 0; x < picw; x++) { int index = y * picw + x; if ( ((Color.red(pix[index]) >= redStart)&&(Color.red(pix[index]) <= redEnd))&& ((Color.green(pix[index]) >= greenStart)&&(Color.green(pix[index]) <= greenEnd))&& ((Color.blue(pix[index]) >= blueStart)&&(Color.blue(pix[index]) <= blueEnd)) ){ pix[index] = colorNew; } } } Bitmap bm = Bitmap.createBitmap(pix, picw, pich,Bitmap.Config.ARGB_8888); return bm; } return null; }
source share