BitmapShader  |  API reference  |  Android Developers


public class BitmapShader
extends Shader



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

Summary

Constants

int FILTER_MODE_DEFAULT

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

int FILTER_MODE_LINEAR

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.

int FILTER_MODE_NEAREST

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

Public constructors

BitmapShader(Bitmap bitmap, Shader.TileMode tileX, Shader.TileMode tileY)

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

Public methods

int getFilterMode()

Returns the filter mode used when sampling from this shader

int getMaxAnisotropy()

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

void setFilterMode(int mode)

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

void setMaxAnisotropy(int maxAnisotropy)

Enables and configures the max anisotropy sampling value.

void setOverrideGainmap(Gainmap overrideGainmap)

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

Inherited methods

From class android.graphics.Shader

boolean getLocalMatrix(Matrix localM)

Return true if the shader has a non-identity local matrix.

void setLocalMatrix(Matrix localM)

Set the shader's local matrix.

From class java.lang.Object

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(long timeoutMillis, int nanos)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait(long timeoutMillis)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait()

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

Constants

FILTER_MODE_DEFAULT

public static final int FILTER_MODE_DEFAULT

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.

Constant Value: 0 (0x00000000)

FILTER_MODE_LINEAR

public static final int FILTER_MODE_LINEAR

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.

Constant Value: 2 (0x00000002)

FILTER_MODE_NEAREST

public static final int FILTER_MODE_NEAREST

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.

Constant Value: 1 (0x00000001)

Public constructors

BitmapShader

public BitmapShader (Bitmap bitmap, 
                Shader.TileMode tileX, 
                Shader.TileMode tileY)

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

getMaxAnisotropy

public int getMaxAnisotropy ()

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

Returns
int

setMaxAnisotropy

public void setMaxAnisotropy (int maxAnisotropy)

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

public void setOverrideGainmap (Gainmap overrideGainmap)

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