androidandroid-imageviewporter-duff

i want to add a color filter to the imageview


I'd like to add a ColorFilter to ImageView.

Currently I'm using:

ImageView iv = (ImageView)findViewById(resIdOfImageToFilter);
iv.setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);

I've checked Multiple Modes in PotterDuff such as SRC_IN, SRC etc., but I'm not getting any difference in any of the modes... All mode turns the whole ImageView in perfect Red color.

I need to blend RED color in the existing image so that image will look with a REDDISH tinge....


Solution

  • The right way to do it was using PorterDuff.Mode.LIGHTEN.

    So the updated code will be like:

    ImageView iv = (ImageView)findViewById(resIdOfImageToFilter);
    iv.setColorFilter(Color.RED, PorterDuff.Mode.LIGHTEN);