在我的应用程序中,我试图改变标记图像的颜色。但这并不是我想要的效果。
Drawable drawable = getDrawable(R.drawable.ic_marker);
drawable.setColorFilter(item.getColor()), PorterDuff.Mode.ADD);可绘制图如下(如下所示),当我添加ColorFilter时,标记得到正确的颜色,白色保持白色,但图像的透明部分也得到颜色。我只想要黑色的改变,而白色和透明的部分必须保持这样。

发布于 2018-06-01 10:20:07
这就是我用setColorFilter、ColorMatrix和ColorMatrixColorFilter做实验的地方。
drawable.setColorFilter(item.getColorMatrix());或
drawable.setColorFilter(new ColorMatrixColorFilter(getColorMatrix5()));//custom 5
//custom 5
private ColorMatrix getColorMatrix5()
{
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.setSaturation(0);//make it greyscale
ColorMatrix blueMatrix = new ColorMatrix(new float[] {
0, 0, 0, 0, 0, // red
0, 0, 0, 0, 0, // green
1, 1, 1, 1, 1, // blue
1, 1, 1, 1, 1 // alpha
});
// Convert, then scale and clamp
colorMatrix.postConcat(blueMatrix);
return colorMatrix;
}//getColorMatrix5见PorterDuff,PorterDuff.Mode,PorterDuffXfermode,ColorFilter,ColorMatrix,ColorMatrixColorFilter,PorterDuffColorFilter,Canvas,Color。
https://stackoverflow.com/questions/49296812
复制相似问题