public static Bitmap changeTintColor ( Bitmap bitmap , int originalColor , int destinationColor ) { // original tint color int [ ] o = new int [ ] { Color . red ( originalColor ) , Color . green ( originalColor ) , Color . blue ( originalColor ) } ; // destination tint color int [ ] d = new int [ ] { Color . red ( destinationColor ) , Color . green ( destinationColor ) , Color . blue ( destinationColor ) } ; int width = bitmap . getWidth ( ) ; int height = bitmap . getHeight ( ) ; int [ ] pixels = new int [ width * height ] ; bitmap . getPixels ( pixels , 0 , width , 0 , 0 , width , height ) ; int maxIndex = getMaxIndex ( o ) ; int mintIndex = getMinIndex ( o ) ; for ( int i = 0 ; i < pixels . length ; i ++ ) { int color = pixels [ i ] ; // pixel color int [ ] p = new int [ ] { Color . red ( color ) , Color . green ( color ) , Color . blue ( color ) } ; int alpha = Color . alpha ( color ) ; float [ ] transformation = calculateTransformation ( o [ maxIndex ] , o [ mintIndex ] , p [ maxIndex ] , p [ mintIndex ] ) ; pixels [ i ] = applyTransformation ( d , alpha , transformation ) ; } return Bitmap . createBitmap ( pixels , width , height , Bitmap . Config . ARGB_8888 ) ; }
Creates a copy of the bitmap by calculating the transformation based on the original color and applying it to the the destination color .