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
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.