{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

ColorFilter.Companion

public static class ColorFilter.Companion


Summary

Public methods

static final @NonNull ColorFilter

Create a ColorFilter that transforms colors through a 4x5 color matrix.

static final @NonNull ColorFilter
lighting(@NonNull Color multiply, @NonNull Color add)

Create a ColorFilter that can be used to simulate simple lighting effects.

static final @NonNull ColorFilter
tint(@NonNull Color color, @NonNull BlendMode blendMode)

Creates a color filter that applies the blend mode given as the second argument.

Public methods

colorMatrix

public static final @NonNull ColorFilter colorMatrix(@NonNull ColorMatrix colorMatrix)

Create a ColorFilter that transforms colors through a 4x5 color matrix. This filter can be used to change the saturation of pixels, convert from YUV to RGB, etc.

Parameters
@NonNull ColorMatrix colorMatrix

ColorMatrix used to transform pixel values when drawn

lighting

public static final @NonNull ColorFilter lighting(@NonNull Color multiply, @NonNull Color add)

Create a ColorFilter that can be used to simulate simple lighting effects. A lighting ColorFilter is defined by two parameters, one used to multiply the source color and one used to add to the source color

Parameters
@NonNull Color multiply

Color that will be added to the source color when the color filter is applied

@NonNull Color add

Color used to multiply the source color when the color filter is applied.

tint

public static final @NonNull ColorFilter tint(@NonNull Color color, @NonNull BlendMode blendMode)

Creates a color filter that applies the blend mode given as the second argument. The source color is the one given as the first argument, and the destination color is the one from the layer being composited.

The output of this filter is then composited into the background according to the Paint.blendMode, using the output of this filter as the source and the background as the destination.

Parameters
@NonNull Color color

Color used to blend source content

@NonNull BlendMode blendMode

BlendMode used when compositing the tint color to the destination