Car*_*ira 19 android colors drawable
可以在Drawable中"反转"颜色吗?你有什么消极的,你知道吗?
我知道可以将Drawable改为黑白......反转颜色怎么样?
谢谢!
Car*_*ira 50
经过一些研究,我发现解决方案比我想象的要简单得多.
这里是:
/**
* 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));
Run Code Online (Sandbox Code Playgroud)
最好的方法是将您的可绘制对象转换为位图:
Bitmap fromDrawable = BitmapFactory.decodeResource(context.getResources(),R.drawable.drawable_resource);
Run Code Online (Sandbox Code Playgroud)
然后将其反转如下:
如果需要,然后返回到可绘制对象:
Drawable invertedDrawable = new BitmapDrawable(getResources(),fromDrawable);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13347 次 |
| 最近记录: |