What color blending algorithm is used to darken a color?
android, colors, java
Solution
If you want darker `Color`, you can:
- Convert your RGB to HSV with `RGBToHSV()`.
- Reduce V (lightness value). It's `hsv[2]`, a float with value from 0 to 1.
- Convert HSV to `Color` with `HSVToColor()`.
If you want darker `Bitmap`, `PorterDuff.Mode.DARKEN` should work. You just need to calibrate `COLOR` value:
private Bitmap getDarkerBitmap(Bitmap src)
{
final int COLOR = 0xAAFFFFFF;
final int WIDTH = src.getWidth();
final int HEIGHT = src.getHeight();
final Bitmap result = Bitmap.createBitmap(WIDTH, HEIGHT, src.getConfig());
final BitmapDrawable drawable = new BitmapDrawable(src);
drawable.setBounds(0, 0, WIDTH, HEIGHT);
drawable.setColorFilter(COLOR, PorterDuff.Mode.DARKEN);
drawable.draw(new Canvas(result));
return result;
}
Problem
I have these cards that have two color shades on them. A main color, and then a darker accent color: The main color is given to me in hex, but not the accent. Can you tell what kind of blend or transformation is being done to the ARGB of the main color to get the darker accent color? If it matters, I'm developing against Android so I've got access to the Color class and ColorFilter so I can apply all that PorterDuff stuff...