setColorFilter not working

后端 未结 10 1459
春和景丽
春和景丽 2020-12-05 12:43

I\'m trying to implement a simple colorfilter on an imageview to turn the black image into a white image. In order to achieve that I do the following:

    we         


        
10条回答
  •  日久生厌
    2020-12-05 13:19

    I was having issues with setColorFilter on a Samsung S3 running 4.3 and the only way I could get the filter to work was by applying it in the draw(Canvas canvas) method:

    public class ColouredDrawable extends BitmapDrawable {
    
    private ColorFilter mColorFilter;
    
    public ColouredDrawable(Bitmap toTransform, int toColour, Resources resources) {
        super(resources, toTransform);
        float[] matrix = {
                0, 0, 0, 0, ((toColour & 0xFF0000) / 0xFFFF),
                0, 0, 0, 0, ((toColour & 0xFF00) / 0xFF),
                0, 0, 0, 0, (toColour & 0xFF),
                0, 0, 0, 1, 0 };
        mColorFilter = new ColorMatrixColorFilter(matrix);
    }
    
    @Override
    public void draw(Canvas canvas) {
        setColorFilter(mColorFilter);
        super.draw(canvas);
    }
    

    Simple applying setColorFilter to the BitmapDrawable didn't seem to have any effect.

提交回复
热议问题