什么颜色混合算法用于使颜色变暗? [英] What color blending algorithm is used to darken a color?

查看:383
本文介绍了什么颜色混合算法用于使颜色变暗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这些卡在他们上有两种颜色。主颜色,然后是更深的强调颜色:

I have these cards that have two color shades on them. A main color, and then a darker accent color:

主颜色以十六进制给我,但不是重音。你能告诉我们要对主色的ARGB进行什么样的混合或者变换,得到更深的重音色?

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?

如果重要的话, Android,所以我可以访问的Color类和ColorFilter,所以我可以应用所有的PorterDuff东西...

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...

推荐答案

c $ c> Color ,您可以:

If you want darker Color, you can:


  1. 使用 RGBToHSV()

  2. 降低V(亮度值)。 hsv [2] ,值为0到1的浮点数。

  3. 将HSV转换为 / code>与 HSVToColor()

  1. Convert your RGB to HSV with RGBToHSV().
  2. Reduce V (lightness value). It's hsv[2], a float with value from 0 to 1.
  3. Convert HSV to Color with HSVToColor().

c> Bitmap
PorterDuff.Mode.DARKEN 应该可以正常工作。您只需要校准 COLOR 值:

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;
}

这篇关于什么颜色混合算法用于使颜色变暗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆