Tone is a color term commonly used by painters. tone a bitmap with specified color, it's like mixing the color pixel by pixel, the color resulting in layering a color dst RGB with a src color RGB is: new_R = dst_R + (src_R - dst_R) amount new_G = dst_G + (src_G - dst_G) amount new_B = dst_B +
(Bitmap bitmap, int color, float amount)
| 96 | * @return |
| 97 | */ |
| 98 | public static Bitmap tone(Bitmap bitmap, int color, float amount) |
| 99 | { |
| 100 | if(BuildConfig.DEBUG && (amount < 0.0f || amount > 1.0f)) |
| 101 | throw new IllegalArgumentException("amount is out of range [0, 1]"); |
| 102 | |
| 103 | if(NATIVE) |
| 104 | { |
| 105 | // FIXME work not as expected |
| 106 | Bitmap result = bitmap.copy(Bitmap.Config.ARGB_8888, true); |
| 107 | nativeTone(result, color, amount); |
| 108 | return result; |
| 109 | } |
| 110 | else |
| 111 | { |
| 112 | final float c = 1.0f - amount; |
| 113 | matrix.setScale(c, c, c, 1.0f); |
| 114 | |
| 115 | final float array[] = matrix.getArray(); |
| 116 | array[ 4] = Color.red(color) * amount; |
| 117 | array[ 9] = Color.green(color) * amount; |
| 118 | array[14] = Color.blue(color) * amount; |
| 119 | // array[19] = Color.alpha(color) * amount; |
| 120 | |
| 121 | ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix); |
| 122 | Paint paint = new Paint(); // (Paint.ANTI_ALIAS_FLAG); |
| 123 | paint.setColorFilter(filter); |
| 124 | |
| 125 | Bitmap result = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); |
| 126 | // result.eraseColor(color & 0x00ffffff); |
| 127 | Canvas canvas = new Canvas(result); |
| 128 | canvas.drawBitmap(bitmap, 0, 0, paint); |
| 129 | |
| 130 | return result; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | public static Bitmap tone(Bitmap bitmap, int color) |
| 135 | { |
no test coverage detected