Android PorterDuff Mode Creating a PorterDuff ColorFilter

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

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:

drawable.setColorFilter(filter);

It can be applied to an ImageView:

imageView.setColorFilter(filter);

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

paint.setColorFilter(filter);


Got any Android Question?