Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

RoundedBitmapDrawable

abstract class RoundedBitmapDrawable : Drawable
kotlin.Any
   ↳ android.graphics.drawable.Drawable
   ↳ androidx.core.graphics.drawable.RoundedBitmapDrawable

A Drawable that wraps a bitmap and can be drawn with rounded corners. You can create a RoundedBitmapDrawable from a file path, an input stream, or from a android.graphics.Bitmap object.

Also see the android.graphics.Bitmap class, which handles the management and transformation of raw bitmap graphics, and should be used when drawing to a android.graphics.Canvas.

Summary

Public methods

open Unit
draw(@NonNull canvas: Canvas)

open Int

Bitmap?

Returns the bitmap used by this drawable to render.

open ColorFilter!

open Float

open Int

Get the gravity used to position/stretch the bitmap within its bounds.

open Int

open Int

open Int

Paint

Returns the paint used to render this drawable.

open Boolean

Indicates whether anti-aliasing is enabled for this drawable.

open Boolean

Indicates whether the mipmap hint is enabled on this drawable's bitmap.

open Boolean

open Unit
setAlpha(alpha: Int)

open Unit

Enables or disables anti-aliasing for this drawable.

open Unit
setCircular(circular: Boolean)

Sets the image shape to circular.

open Unit

open Unit
setCornerRadius(cornerRadius: Float)

Sets the corner radius to be applied when drawing the bitmap.

open Unit
setDither(dither: Boolean)

open Unit

open Unit
setGravity(gravity: Int)

Set the gravity used to position/stretch the bitmap within its bounds.

open Unit
setMipMap(mipMap: Boolean)

Enables or disables the mipmap hint for this drawable's bitmap.

open Unit
setTargetDensity(@NonNull canvas: Canvas)

Set the density scale at which this drawable will be rendered.

open Unit
setTargetDensity(@NonNull metrics: DisplayMetrics)

Set the density scale at which this drawable will be rendered.

open Unit

Set the density at which this drawable will be rendered.

Protected methods

open Unit
onBoundsChange(bounds: Rect!)

Public methods

draw

open fun draw(@NonNull canvas: Canvas): Unit

getAlpha

open fun getAlpha(): Int

getBitmap

@Nullable fun getBitmap(): Bitmap?

Returns the bitmap used by this drawable to render. May be null.

getColorFilter

open fun getColorFilter(): ColorFilter!

getCornerRadius

open fun getCornerRadius(): Float
Return
Float: The corner radius applied when drawing the bitmap.

getGravity

open fun getGravity(): Int

Get the gravity used to position/stretch the bitmap within its bounds.

Return
Int: the gravity applied to the bitmap

getIntrinsicHeight

open fun getIntrinsicHeight(): Int

getIntrinsicWidth

open fun getIntrinsicWidth(): Int

getOpacity

open fun getOpacity(): Int

getPaint

@NonNull fun getPaint(): Paint

Returns the paint used to render this drawable.

hasAntiAlias

open fun hasAntiAlias(): Boolean

Indicates whether anti-aliasing is enabled for this drawable.

Return
Boolean: True if anti-aliasing is enabled, false otherwise.

hasMipMap

open fun hasMipMap(): Boolean

Indicates whether the mipmap hint is enabled on this drawable's bitmap.

Return
Boolean: True if the mipmap hint is set, false otherwise. If the bitmap is null, this method always returns false.

isCircular

open fun isCircular(): Boolean
Return
Boolean: true if the image is circular, else false.

setAlpha

open fun setAlpha(alpha: Int): Unit

setAntiAlias

open fun setAntiAlias(aa: Boolean): Unit

Enables or disables anti-aliasing for this drawable. Anti-aliasing affects the edges of the bitmap only so it applies only when the drawable is rotated.

Parameters
aa Boolean: True if the bitmap should be anti-aliased, false otherwise.

See Also

setCircular

open fun setCircular(circular: Boolean): Unit

Sets the image shape to circular.

This overwrites any calls made to setCornerRadius(float) so far.

setColorFilter

open fun setColorFilter(cf: ColorFilter!): Unit

setCornerRadius

open fun setCornerRadius(cornerRadius: Float): Unit

Sets the corner radius to be applied when drawing the bitmap.

setDither

open fun setDither(dither: Boolean): Unit

setFilterBitmap

open fun setFilterBitmap(filter: Boolean): Unit

setGravity

open fun setGravity(gravity: Int): Unit

Set the gravity used to position/stretch the bitmap within its bounds.

Parameters
gravity Int: the gravity

setMipMap

open fun setMipMap(mipMap: Boolean): Unit

Enables or disables the mipmap hint for this drawable's bitmap. See Bitmap#setHasMipMap(boolean) for more information. If the bitmap is null, or the current API version does not support setting a mipmap hint, calling this method has no effect.

Parameters
mipMap Boolean: True if the bitmap should use mipmaps, false otherwise.

See Also

setTargetDensity

open fun setTargetDensity(@NonNull canvas: Canvas): Unit

Set the density scale at which this drawable will be rendered. This method assumes the drawable will be rendered at the same density as the specified canvas.

Parameters
canvas Canvas: The Canvas from which the density scale must be obtained.

setTargetDensity

open fun setTargetDensity(@NonNull metrics: DisplayMetrics): Unit

Set the density scale at which this drawable will be rendered.

Parameters
metrics DisplayMetrics: The DisplayMetrics indicating the density scale for this drawable.

setTargetDensity

open fun setTargetDensity(density: Int): Unit

Set the density at which this drawable will be rendered.

Parameters
density Int: The density scale for this drawable.

Protected methods

onBoundsChange

protected open fun onBoundsChange(bounds: Rect!): Unit