Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/graphics/BitmapShader#constants) \| [Ctors](https://developer.android.com/reference/android/graphics/BitmapShader#pubctors) \| [Methods](https://developer.android.com/reference/android/graphics/BitmapShader#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/graphics/BitmapShader#inhmethods)

# BitmapShader

*** ** * ** ***

` public class BitmapShader `   
` ` ` extends https://developer.android.com/reference/android/graphics/Shader ` ` `

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) |||
| ↳ | [android.graphics.Shader](https://developer.android.com/reference/android/graphics/Shader) ||
|   | ↳ | android.graphics.BitmapShader |

<br />

*** ** * ** ***

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

## Summary

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/graphics/BitmapShader#FILTER_MODE_DEFAULT` This FilterMode value will respect the value of the Paint#isFilterBitmap flag while the shader is attached to the Paint. |
| `int` | `https://developer.android.com/reference/android/graphics/BitmapShader#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` | `https://developer.android.com/reference/android/graphics/BitmapShader#FILTER_MODE_NEAREST` This FilterMode value will cause the shader to sample from the nearest pixel to the requested sample point. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/graphics/BitmapShader#BitmapShader(android.graphics.Bitmap,%20android.graphics.Shader.TileMode,%20android.graphics.Shader.TileMode)(https://developer.android.com/reference/android/graphics/Bitmap bitmap, https://developer.android.com/reference/android/graphics/Shader.TileMode tileX, https://developer.android.com/reference/android/graphics/Shader.TileMode tileY) ` Call this to create a new shader that will draw with a bitmap. |

| ### Public methods ||
|---|---|
| ` int` | ` https://developer.android.com/reference/android/graphics/BitmapShader#getFilterMode()() ` Returns the filter mode used when sampling from this shader |
| ` int` | ` https://developer.android.com/reference/android/graphics/BitmapShader#getMaxAnisotropy()() ` Returns the current max anisotropic filtering value configured by `https://developer.android.com/reference/android/graphics/BitmapShader#setFilterMode(int)`. |
| ` void` | ` https://developer.android.com/reference/android/graphics/BitmapShader#setFilterMode(int)(int mode) ` Set the filter mode to be used when sampling from this shader. |
| ` void` | ` https://developer.android.com/reference/android/graphics/BitmapShader#setMaxAnisotropy(int)(int maxAnisotropy) ` Enables and configures the max anisotropy sampling value. |
| ` void` | ` https://developer.android.com/reference/android/graphics/BitmapShader#setOverrideGainmap(android.graphics.Gainmap)(https://developer.android.com/reference/android/graphics/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 ` https://developer.android.com/reference/android/graphics/Shader ` ` boolean` ` https://developer.android.com/reference/android/graphics/Shader#getLocalMatrix(android.graphics.Matrix)(https://developer.android.com/reference/android/graphics/Matrix localM) `

Return true if the shader has a non-identity local matrix.
` void` ` https://developer.android.com/reference/android/graphics/Shader#setLocalMatrix(android.graphics.Matrix)(https://developer.android.com/reference/android/graphics/Matrix localM) `

Set the shader's local matrix.
From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(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` ` https://developer.android.com/reference/java/lang/Object#wait(long)(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` ` https://developer.android.com/reference/java/lang/Object#wait()() `

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

## Constants

### FILTER_MODE_DEFAULT

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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.

<br />

<br />

**See also:**

- `https://developer.android.com/reference/android/graphics/BitmapShader#setFilterMode(int)`

Constant Value: 0 (0x00000000)

### FILTER_MODE_LINEAR

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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.

<br />

<br />

**See also:**

- `https://developer.android.com/reference/android/graphics/BitmapShader#setFilterMode(int)`

Constant Value: 2 (0x00000002)

### FILTER_MODE_NEAREST

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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.

<br />

<br />

**See also:**

- `https://developer.android.com/reference/android/graphics/BitmapShader#setFilterMode(int)`

Constant Value: 1 (0x00000001)

## Public constructors

### BitmapShader

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

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

<br />

| Parameters ||
|---|---|
| `bitmap` | `Bitmap`: The bitmap to use inside the shader. This value cannot be `null`. <br /> |
| `tileX` | `Shader.TileMode`: The tiling mode for x to draw the bitmap in. This value cannot be `null`. <br /> |
| `tileY` | `Shader.TileMode`: The tiling mode for y to draw the bitmap in. This value cannot be `null`. <br /> |

## Public methods

### getFilterMode

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getFilterMode ()
```

Returns the filter mode used when sampling from this shader

<br />

| Returns ||
|---|---|
| `int` | Value is one of the following: - `https://developer.android.com/reference/android/graphics/BitmapShader#FILTER_MODE_DEFAULT` - `https://developer.android.com/reference/android/graphics/BitmapShader#FILTER_MODE_NEAREST` - `https://developer.android.com/reference/android/graphics/BitmapShader#FILTER_MODE_LINEAR` |

### getMaxAnisotropy

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getMaxAnisotropy ()
```

Returns the current max anisotropic filtering value configured by `https://developer.android.com/reference/android/graphics/BitmapShader#setFilterMode(int)`. If `https://developer.android.com/reference/android/graphics/BitmapShader#setFilterMode(int)` is invoked this returns zero.

<br />

| Returns ||
|---|---|
| `int` | <br /> |

### setFilterMode

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setFilterMode (int mode)
```

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 `https://developer.android.com/reference/android/graphics/BitmapShader#setMaxAnisotropy(int)` is ignored.

<br />

| Parameters ||
|---|---|
| `mode` | `int`: Value is one of the following: - `https://developer.android.com/reference/android/graphics/BitmapShader#FILTER_MODE_DEFAULT` - `https://developer.android.com/reference/android/graphics/BitmapShader#FILTER_MODE_NEAREST` - `https://developer.android.com/reference/android/graphics/BitmapShader#FILTER_MODE_LINEAR` |

### setMaxAnisotropy

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setMaxAnisotropy (int maxAnisotropy)
```

Enables and configures the max anisotropy sampling value. If this value is configured, `https://developer.android.com/reference/android/graphics/BitmapShader#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.

<br />

| Parameters ||
|---|---|
| `maxAnisotropy` | `int`: The Anisotropy value to use for filtering. Must be greater than 0. Value is 1 or greater <br /> |

### setOverrideGainmap

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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

<br />

| Parameters ||
|---|---|
| `overrideGainmap` | `Gainmap`: The gainmap to draw instead, null to use any gainmap on the Bitmap <br /> |