Android Creating a PorterDuff ColorFilter


PorterDuff.Mode is used to create a PorterDuffColorFilter. A color filter modifies the color of each pixel of a visual resource.

ColorFilter filter = new PorterDuffColorFilter(Color.BLUE, PorterDuff.Mode.SRC_IN);

The above filter will tint the non-transparent pixels to blue color.

The color filter can be applied to a Drawable:


It can be applied to an ImageView:


Also, it can be applied to a Paint, so that the color that is drawn using that paint, is modified by the filter: