Added in API level 1

BitmapShader

open class BitmapShader : Shader
kotlin.Any
   ↳ android.graphics.Shader
   ↳ android.graphics.BitmapShader

Shader used to draw a bitmap as a texture. The bitmap can be repeated or mirrored by setting the tiling mode.

Summary

Constants
static Int

This FilterMode value will respect the value of the Paint#isFilterBitmap flag while the shader is attached to the Paint.

static Int

This FilterMode value will cause the shader to interpolate the output of the shader from a 2x2 grid of pixels nearest to the sample point (i.e. bilinear interpolation).

static Int

This FilterMode value will cause the shader to sample from the nearest pixel to the requested sample point.

Public constructors

Call this to create a new shader that will draw with a bitmap.

Public methods
open Int

Returns the filter mode used when sampling from this shader

open Int

Returns the current max anisotropic filtering value configured by setFilterMode(int).

open Unit

Set the filter mode to be used when sampling from this shader.

open Unit
setMaxAnisotropy(maxAnisotropy: Int)

Enables and configures the max anisotropy sampling value.

open Unit
setOverrideGainmap(overrideGainmap: Gainmap?)

Draws the BitmapShader with a copy of the given gainmap instead of the gainmap on the Bitmap the shader was constructed from

Inherited functions

Constants

FILTER_MODE_DEFAULT

Added in API level 33
static val FILTER_MODE_DEFAULT: Int

This FilterMode value will respect the value of the Paint#isFilterBitmap flag while the shader is attached to the Paint.

The exception to this rule is when a Shader is attached as input to a RuntimeShader. In that case this mode will default to FILTER_MODE_NEAREST.

Value: 0

FILTER_MODE_LINEAR

Added in API level 33
static val FILTER_MODE_LINEAR: Int

This FilterMode value will cause the shader to interpolate the output of the shader from a 2x2 grid of pixels nearest to the sample point (i.e. bilinear interpolation).

This value will override the effect of Paint#isFilterBitmap.

Value: 2

FILTER_MODE_NEAREST

Added in API level 33
static val FILTER_MODE_NEAREST: Int

This FilterMode value will cause the shader to sample from the nearest pixel to the requested sample point.

This value will override the effect of Paint#isFilterBitmap.

Value: 1

Public constructors

BitmapShader

Added in API level 1
BitmapShader(
    bitmap: Bitmap,
    tileX: Shader.TileMode,
    tileY: Shader.TileMode)

Call this to create a new shader that will draw with a bitmap.

Parameters
bitmap Bitmap: The bitmap to use inside the shader This value cannot be null.
tileX Shader.TileMode: The tiling mode for x to draw the bitmap in. This value cannot be null.
tileY Shader.TileMode: The tiling mode for y to draw the bitmap in. This value cannot be null.

Public methods

getFilterMode

Added in API level 33
open fun getFilterMode(): Int

Returns the filter mode used when sampling from this shader

Return
Int Value is android.graphics.BitmapShader#FILTER_MODE_DEFAULT, android.graphics.BitmapShader#FILTER_MODE_NEAREST, or android.graphics.BitmapShader#FILTER_MODE_LINEAR

getMaxAnisotropy

Added in API level 34
open fun getMaxAnisotropy(): Int

Returns the current max anisotropic filtering value configured by setFilterMode(int). If setFilterMode(int) is invoked this returns zero.

setFilterMode

Added in API level 33
open fun setFilterMode(mode: Int): Unit

Set the filter mode to be used when sampling from this shader. If this is configured then the anisotropic filtering value specified in any previous call to setMaxAnisotropy(int) is ignored.

Parameters
mode Int: Value is android.graphics.BitmapShader#FILTER_MODE_DEFAULT, android.graphics.BitmapShader#FILTER_MODE_NEAREST, or android.graphics.BitmapShader#FILTER_MODE_LINEAR

setMaxAnisotropy

Added in API level 34
open fun setMaxAnisotropy(maxAnisotropy: Int): Unit

Enables and configures the max anisotropy sampling value. If this value is configured, setFilterMode(int) is ignored. Anisotropic filtering can enhance visual quality by removing aliasing effects of images that are at oblique viewing angles. This value is typically consumed as a power of 2 and anisotropic values of the next power of 2 typically provide twice the quality improvement as the previous value. For example, a sampling value of 4 would provide twice the improvement of a sampling value of 2. It is important to note that higher sampling values reach diminishing returns as the improvements between 8 and 16 can be slight.

Parameters
maxAnisotropy Int: The Anisotropy value to use for filtering. Must be greater than 0. Value is 1 or greater

setOverrideGainmap

open fun setOverrideGainmap(overrideGainmap: Gainmap?): Unit

Draws the BitmapShader with a copy of the given gainmap instead of the gainmap on the Bitmap the shader was constructed from

Parameters
overrideGainmap Gainmap?: The gainmap to draw instead, null to use any gainmap on the Bitmap