Added in API level 31

RenderEffect


public final class RenderEffect
extends Object

java.lang.Object
   ↳ android.graphics.RenderEffect


Intermediate rendering step used to render drawing commands with a corresponding visual effect. A RenderEffect can be configured on a RenderNode through RenderNode#setRenderEffect(RenderEffect) and will be applied when drawn through Canvas#drawRenderNode(RenderNode). Additionally a RenderEffect can be applied to a View's backing RenderNode through View.setRenderEffect(RenderEffect)

Summary

Public methods

static RenderEffect createBitmapEffect(Bitmap bitmap)

Create a RenderEffect that renders the contents of the input Bitmap.

static RenderEffect createBitmapEffect(Bitmap bitmap, Rect src, Rect dst)

Create a RenderEffect that renders the contents of the input Bitmap.

static RenderEffect createBlendModeEffect(RenderEffect dst, RenderEffect src, BlendMode blendMode)

Create a RenderEffect that is a composition of 2 other RenderEffect instances combined by the specified BlendMode

static RenderEffect createBlurEffect(float radiusX, float radiusY, Shader.TileMode edgeTreatment)

Create a RenderEffect that blurs the contents of the RenderNode that this RenderEffect is installed on with the specified radius along the x and y axis.

static RenderEffect createBlurEffect(float radiusX, float radiusY, RenderEffect inputEffect, Shader.TileMode edgeTreatment)

Create a RenderEffect that blurs the contents of the optional input RenderEffect with the specified radius along the x and y axis.

static RenderEffect createChainEffect(RenderEffect outer, RenderEffect inner)

Create a RenderEffect that composes 'inner' with 'outer', such that the results of 'inner' are treated as the source bitmap passed to 'outer', i.e.

static RenderEffect createColorFilterEffect(ColorFilter colorFilter, RenderEffect renderEffect)

Create a RenderEffect that applies the color filter to the provided RenderEffect

static RenderEffect createColorFilterEffect(ColorFilter colorFilter)

Create a RenderEffect that applies the color filter to the contents of the RenderNode that this RenderEffect is installed on

static RenderEffect createOffsetEffect(float offsetX, float offsetY, RenderEffect input)

Create a RenderEffect instance with the provided x and y offset

static RenderEffect createOffsetEffect(float offsetX, float offsetY)

Create a RenderEffect instance that will offset the drawing content by the provided x and y offset.

static RenderEffect createRuntimeShaderEffect(RuntimeShader shader, String uniformShaderName)

Create a RenderEffect that executes the provided RuntimeShader and passes the contents of the RenderNode that this RenderEffect is installed on as an input to the shader.

static RenderEffect createShaderEffect(Shader shader)

Create a RenderEffect that renders the contents of the input Shader.

Inherited methods

Public methods

createBitmapEffect

Added in API level 31
public static RenderEffect createBitmapEffect (Bitmap bitmap)

Create a RenderEffect that renders the contents of the input Bitmap. This is useful to create an input for other RenderEffect types such as RenderEffect#createBlurEffect(float, float, RenderEffect, TileMode) or RenderEffect#createColorFilterEffect(ColorFilter, RenderEffect)

Parameters
bitmap Bitmap: The source bitmap to be rendered by the created RenderEffect This value cannot be null.

Returns
RenderEffect This value cannot be null.

createBitmapEffect

Added in API level 31
public static RenderEffect createBitmapEffect (Bitmap bitmap, 
                Rect src, 
                Rect dst)

Create a RenderEffect that renders the contents of the input Bitmap. This is useful to create an input for other RenderEffect types such as RenderEffect#createBlurEffect(float, float, RenderEffect, TileMode) or RenderEffect#createColorFilterEffect(ColorFilter, RenderEffect)

Parameters
bitmap Bitmap: The source bitmap to be rendered by the created RenderEffect This value cannot be null.

src Rect: Optional subset of the bitmap to be part of the rendered output. If null is provided, the entire bitmap bounds are used.

dst Rect: Bounds of the destination which the bitmap is translated and scaled to be drawn into within the bounds of the RenderNode this RenderEffect is installed on This value cannot be null.

Returns
RenderEffect This value cannot be null.

createBlendModeEffect

Added in API level 31
public static RenderEffect createBlendModeEffect (RenderEffect dst, 
                RenderEffect src, 
                BlendMode blendMode)

Create a RenderEffect that is a composition of 2 other RenderEffect instances combined by the specified BlendMode

Parameters
dst RenderEffect: The Dst pixels used in blending This value cannot be null.

src RenderEffect: The Src pixels used in blending This value cannot be null.

blendMode BlendMode: The BlendMode to be used to combine colors from the two RenderEffects This value cannot be null.

Returns
RenderEffect This value cannot be null.

createBlurEffect

Added in API level 31
public static RenderEffect createBlurEffect (float radiusX, 
                float radiusY, 
                Shader.TileMode edgeTreatment)

Create a RenderEffect that blurs the contents of the RenderNode that this RenderEffect is installed on with the specified radius along the x and y axis.

Parameters
radiusX float: Radius of blur along the X axis

radiusY float: Radius of blur along the Y axis

edgeTreatment Shader.TileMode: Policy for how to blur content near edges of the blur kernel This value cannot be null.

Returns
RenderEffect This value cannot be null.

createBlurEffect

Added in API level 31
public static RenderEffect createBlurEffect (float radiusX, 
                float radiusY, 
                RenderEffect inputEffect, 
                Shader.TileMode edgeTreatment)

Create a RenderEffect that blurs the contents of the optional input RenderEffect with the specified radius along the x and y axis. If no input RenderEffect is provided then all drawing commands issued with a RenderNode that this RenderEffect is installed in will be blurred

Parameters
radiusX float: Radius of blur along the X axis

radiusY float: Radius of blur along the Y axis

inputEffect RenderEffect: Input RenderEffect that provides the content to be blurred, can be null to indicate that the drawing commands on the RenderNode are to be blurred instead of the input RenderEffect

edgeTreatment Shader.TileMode: Policy for how to blur content near edges of the blur kernel This value cannot be null.

Returns
RenderEffect This value cannot be null.

createChainEffect

Added in API level 31
public static RenderEffect createChainEffect (RenderEffect outer, 
                RenderEffect inner)

Create a RenderEffect that composes 'inner' with 'outer', such that the results of 'inner' are treated as the source bitmap passed to 'outer', i.e.

 result = outer(inner(source))
 
 
Consumers should favor explicit chaining of RenderEffect instances at creation time rather than using chain effect. Chain effects are useful for situations where the input or output are provided from elsewhere and the input or output RenderEffect need to be changed.

Parameters
outer RenderEffect: RenderEffect that consumes the output of as its input This value cannot be null.

inner RenderEffect: RenderEffect that is consumed as input by This value cannot be null.

Returns
RenderEffect This value cannot be null.

createColorFilterEffect

Added in API level 31
public static RenderEffect createColorFilterEffect (ColorFilter colorFilter, 
                RenderEffect renderEffect)

Create a RenderEffect that applies the color filter to the provided RenderEffect

Parameters
colorFilter ColorFilter: ColorFilter applied to the content in the input RenderEffect This value cannot be null.

renderEffect RenderEffect: Source to be transformed by the specified ColorFilter This value cannot be null.

Returns
RenderEffect This value cannot be null.

createColorFilterEffect

Added in API level 31
public static RenderEffect createColorFilterEffect (ColorFilter colorFilter)

Create a RenderEffect that applies the color filter to the contents of the RenderNode that this RenderEffect is installed on

Parameters
colorFilter ColorFilter: ColorFilter applied to the content in the input RenderEffect This value cannot be null.

Returns
RenderEffect This value cannot be null.

createOffsetEffect

Added in API level 31
public static RenderEffect createOffsetEffect (float offsetX, 
                float offsetY, 
                RenderEffect input)

Create a RenderEffect instance with the provided x and y offset

Parameters
offsetX float: offset along the x axis in pixels

offsetY float: offset along the y axis in pixels

input RenderEffect: target RenderEffect used to render in the offset coordinates. This value cannot be null.

Returns
RenderEffect This value cannot be null.

createOffsetEffect

Added in API level 31
public static RenderEffect createOffsetEffect (float offsetX, 
                float offsetY)

Create a RenderEffect instance that will offset the drawing content by the provided x and y offset.

Parameters
offsetX float: offset along the x axis in pixels

offsetY float: offset along the y axis in pixels

Returns
RenderEffect This value cannot be null.

createRuntimeShaderEffect

Added in API level 33
public static RenderEffect createRuntimeShaderEffect (RuntimeShader shader, 
                String uniformShaderName)

Create a RenderEffect that executes the provided RuntimeShader and passes the contents of the RenderNode that this RenderEffect is installed on as an input to the shader.

Parameters
shader RuntimeShader: the runtime shader that will bind the inputShaderName to the RenderEffect input This value cannot be null.

uniformShaderName String: the uniform name defined in the RuntimeShader's program to which the contents of the RenderNode will be bound This value cannot be null.

Returns
RenderEffect This value cannot be null.

createShaderEffect

Added in API level 31
public static RenderEffect createShaderEffect (Shader shader)

Create a RenderEffect that renders the contents of the input Shader. This is useful to create an input for other RenderEffect types such as RenderEffect#createBlurEffect(float, float, RenderEffect, TileMode) RenderEffect#createBlurEffect(float, float, RenderEffect, TileMode) or RenderEffect#createColorFilterEffect(ColorFilter, RenderEffect).

Parameters
shader Shader: This value cannot be null.

Returns
RenderEffect This value cannot be null.