# BitmapCompat

# BitmapCompat

Artifact:[androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core)  
[View Source](https://cs.android.com/search?q=file:androidx/core/graphics/BitmapCompat.java+class:androidx.core.graphics.BitmapCompat)  
Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/core/graphics/BitmapCompat "View this page in Java")

<br />

```
class BitmapCompat
```

<br />

*** ** * ** ***

Helper for accessing features in[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html).

## Summary

|                                       ### Public functions                                        |
|---------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html)      | [createScaledBitmap](https://developer.android.com/reference/kotlin/androidx/core/graphics/BitmapCompat#createScaledBitmap(android.graphics.Bitmap,int,int,android.graphics.Rect,boolean))`(` ` srcBm: `[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html)`,` ` dstW: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` dstH: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` srcRect: `[Rect](https://developer.android.com/reference/android/graphics/Rect.html)`?,` ` scaleInLinearSpace: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) `)` Return a scaled bitmap. |
| `java-static `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)         | `@`[ReplaceWith](https://developer.android.com/reference/kotlin/androidx/annotation/ReplaceWith)`(expression = "bitmap.getAllocationByteCount()")` ~~[getAllocationByteCount](https://developer.android.com/reference/kotlin/androidx/core/graphics/BitmapCompat#getAllocationByteCount(android.graphics.Bitmap))~~`(bitmap: `[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html)`)` **This function is deprecated.** Call[getAllocationByteCount](https://developer.android.com/reference/android/graphics/Bitmap.html#getAllocationByteCount())directly. <br />                                                                                                                |
| `java-static `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | `@`[ReplaceWith](https://developer.android.com/reference/kotlin/androidx/annotation/ReplaceWith)`(expression = "bitmap.hasMipMap()")` ~~[hasMipMap](https://developer.android.com/reference/kotlin/androidx/core/graphics/BitmapCompat#hasMipMap(android.graphics.Bitmap))~~`(bitmap: `[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html)`)` **This function is deprecated.** Call[hasMipMap](https://developer.android.com/reference/android/graphics/Bitmap.html#hasMipMap())directly. <br />                                                                                                                                                                                 |
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | `@`[ReplaceWith](https://developer.android.com/reference/kotlin/androidx/annotation/ReplaceWith)`(expression = "bitmap.setHasMipMap(hasMipMap)")` ~~[setHasMipMap](https://developer.android.com/reference/kotlin/androidx/core/graphics/BitmapCompat#setHasMipMap(android.graphics.Bitmap,boolean))~~`(bitmap: `[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html)`, hasMipMap: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` **This function is deprecated.** Call setHasMipMap directly. <br />                                                                                                                                    |

## Public functions

### createScaledBitmap

Added in[1.8.0](https://developer.android.com/jetpack/androidx/releases/core#1.8.0)  

```
java-static fun createScaledBitmap(
    srcBm: Bitmap,
    dstW: Int,
    dstH: Int,
    srcRect: Rect?,
    scaleInLinearSpace: Boolean
): Bitmap
```

Return a scaled bitmap.

This algorithm is intended for downscaling by large ratios when high quality is desired. It is similar to the creation of mipmaps, but stops at the desired size. Visually, the result is smoother and softer than[createScaledBitmap](https://developer.android.com/reference/android/graphics/Bitmap.html#createScaledBitmap(android.graphics.Bitmap, int, int, boolean))

The returned bitmap will always be a mutable copy with a config matching the input except in the following scenarios:

1. The source bitmap is returned and the source bitmap is immutable.
2. The source bitmap is a`HARDWARE`bitmap. For this input, a mutable non-`HARDWARE`Bitmap is returned. On API 31 and up, the internal format of the HardwareBuffer is read to determine the underlying format, and the returned Bitmap will use a Config to match. Pre-31, the returned Bitmap will be`ARGB_8888`.

|                                                Parameters                                                 |
|-----------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `srcBm: `[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html)                   | A source bitmap. It will not be altered.                                                                                                                                              |
| `dstW: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                       | The output width                                                                                                                                                                      |
| `dstH: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                       | The output height                                                                                                                                                                     |
| `srcRect: `[Rect](https://developer.android.com/reference/android/graphics/Rect.html)`?`                  | Uses a region of the input bitmap as the source.                                                                                                                                      |
| `scaleInLinearSpace: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | When true, uses`LINEAR_EXTENDED_SRGB`as a color space when scaling. Otherwise, uses the color space of the input bitmap. (On API level 26 and earlier, this parameter has no effect). |

|                                    Returns                                     |
|--------------------------------------------------------------------------------|-------------------------------------|
| [Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html) | A new bitmap in the requested size. |

### getAllocationByteCount

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  
Deprecated in[1.15.0](https://developer.android.com/jetpack/androidx/releases/core#1.15.0)  

```
@ReplaceWith(expression = "bitmap.getAllocationByteCount()")
java-static fun [getAllocationByteCount](https://developer.android.com/reference/kotlin/androidx/core/graphics/BitmapCompat#getAllocationByteCount(android.graphics.Bitmap))(bitmap: Bitmap): Int
```
| **This function is deprecated.**   
|
| Call[getAllocationByteCount](https://developer.android.com/reference/android/graphics/Bitmap.html#getAllocationByteCount())directly.

Returns the size of the allocated memory used to store this bitmap's pixels.

This value will not change over the lifetime of a Bitmap.  

|                                                        See also                                                         |
|-------------------------------------------------------------------------------------------------------------------------|---|
| [getAllocationByteCount](https://developer.android.com/reference/android/graphics/Bitmap.html#getAllocationByteCount()) |   |

### hasMipMap

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  
Deprecated in[1.15.0](https://developer.android.com/jetpack/androidx/releases/core#1.15.0)  

```
@ReplaceWith(expression = "bitmap.hasMipMap()")
java-static fun [hasMipMap](https://developer.android.com/reference/kotlin/androidx/core/graphics/BitmapCompat#hasMipMap(android.graphics.Bitmap))(bitmap: Bitmap): Boolean
```
| **This function is deprecated.**   
|
| Call[hasMipMap](https://developer.android.com/reference/android/graphics/Bitmap.html#hasMipMap())directly.

Indicates whether the renderer responsible for drawing this bitmap should attempt to use mipmaps when this bitmap is drawn scaled down.

If you know that you are going to draw this bitmap at less than 50% of its original size, you may be able to obtain a higher quality

This property is only a suggestion that can be ignored by the renderer. It is not guaranteed to have any effect.  

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|---------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | true if the renderer should attempt to use mipmaps, false otherwise |

|                                           See also                                            |
|-----------------------------------------------------------------------------------------------|---|
| [hasMipMap](https://developer.android.com/reference/android/graphics/Bitmap.html#hasMipMap()) |   |

### setHasMipMap

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  
Deprecated in[1.15.0](https://developer.android.com/jetpack/androidx/releases/core#1.15.0)  

```
@ReplaceWith(expression = "bitmap.setHasMipMap(hasMipMap)")
java-static fun [setHasMipMap](https://developer.android.com/reference/kotlin/androidx/core/graphics/BitmapCompat#setHasMipMap(android.graphics.Bitmap,boolean))(bitmap: Bitmap, hasMipMap: Boolean): Unit
```
| **This function is deprecated.**   
|
| Call setHasMipMap directly.

Set a hint for the renderer responsible for drawing this bitmap indicating that it should attempt to use mipmaps when this bitmap is drawn scaled down.

If you know that you are going to draw this bitmap at less than 50% of its original size, you may be able to obtain a higher quality by turning this property on.

Note that if the renderer respects this hint it might have to allocate extra memory to hold the mipmap levels for this bitmap.

This property is only a suggestion that can be ignored by the renderer. It is not guaranteed to have any effect.  

|                                            Parameters                                            |
|--------------------------------------------------------------------------------------------------|--------------------------------------------------------------|
| `bitmap: `[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html)         | bitmap for which to set the state.                           |
| `hasMipMap: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | indicates whether the renderer should attempt to use mipmaps |

|                                                  See also                                                  |
|------------------------------------------------------------------------------------------------------------|---|
| [setHasMipMap](https://developer.android.com/reference/android/graphics/Bitmap.html#setHasMipMap(boolean)) |   |