要使可绘制的图像灰度化,我需要:
ColorMatrix matrix = new ColorMatrix();
matrix.setSaturation(200);
ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
drawable.setColorFilter(filter);
作为Justin said。它工作得很好。
我正在使用svg android库。所以我试着:
PictureDrawable pictureDrawable = svg.createPictureDrawable();
ColorMatrix matrix = new ColorMatrix();
matrix.setSaturation(200);
ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
pictureDrawable.setColorFilter(filter);
imageView.setImageDrawable(pictureDrawable);
但什么也没发生…怎么了?
最佳答案
恐怕我在android源代码中找到了原因:
drawable.java语言
public abstract void setColorFilter(ColorFilter cf);
picturedrawable.java网站
@Override
public void setColorFilter(ColorFilter colorFilter) {}
简单地说,任何对
setColorFilter
的调用对于PictureDrawable
s都是无用的。关于android - 灰度PictureDrawable,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10770976/