反转可绘制的颜色 [英] Invert colors of drawable

查看:113
本文介绍了反转可绘制的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将Drawable中的颜色反转"?你知道负片的种类吗?

Is it possible to "invert" colors in a Drawable? Kind of what you have in a negative, you know?

我知道可以将Drawable更改为黑白,但是反转颜色呢?

I know it's possible to change a Drawable to black and white, but what about inverting colors?

推荐答案

经过研究,我发现解决方案比我想象的要简单得多.

After some research I found out that solution is much simpler than I thought.

这里是:

  /**
   * Color matrix that flips the components (<code>-1.0f * c + 255 = 255 - c</code>)
   * and keeps the alpha intact.
   */
  private static final float[] NEGATIVE = { 
    -1.0f,     0,     0,    0, 255, // red
        0, -1.0f,     0,    0, 255, // green
        0,     0, -1.0f,    0, 255, // blue
        0,     0,     0, 1.0f,   0  // alpha  
  };

  drawable.setColorFilter(new ColorMatrixColorFilter(NEGATIVE));

这篇关于反转可绘制的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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