added in version 22.1.0
belongs to Maven artifact com.android.support:support-compat:28.0.0-alpha1

RoundedBitmapDrawable

public abstract class RoundedBitmapDrawable
extends Drawable

java.lang.Object
   ↳ android.graphics.drawable.Drawable
     ↳ android.support.v4.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 Bitmap object.

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

Summary

Public methods

void draw(Canvas canvas)
int getAlpha()
final Bitmap getBitmap()

Returns the bitmap used by this drawable to render.

ColorFilter getColorFilter()
float getCornerRadius()
int getGravity()

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

int getIntrinsicHeight()
int getIntrinsicWidth()
int getOpacity()
final Paint getPaint()

Returns the paint used to render this drawable.

boolean hasAntiAlias()

Indicates whether anti-aliasing is enabled for this drawable.

boolean hasMipMap()

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

boolean isCircular()
void setAlpha(int alpha)
void setAntiAlias(boolean aa)

Enables or disables anti-aliasing for this drawable.

void setCircular(boolean circular)

Sets the image shape to circular.

void setColorFilter(ColorFilter cf)
void setCornerRadius(float cornerRadius)

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

void setDither(boolean dither)
void setFilterBitmap(boolean filter)
void setGravity(int gravity)

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

void setMipMap(boolean mipMap)

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

void setTargetDensity(DisplayMetrics metrics)

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

void setTargetDensity(Canvas canvas)

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

void setTargetDensity(int density)

Set the density at which this drawable will be rendered.

Protected methods

void onBoundsChange(Rect bounds)

Inherited methods

From class android.graphics.drawable.Drawable
From class java.lang.Object

Public methods

draw

added in version 22.1.0
void draw (Canvas canvas)

Parameters
canvas Canvas

getAlpha

int getAlpha ()

Returns
int

getBitmap

added in version 22.1.0
Bitmap getBitmap ()

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

Returns
Bitmap

getColorFilter

ColorFilter getColorFilter ()

Returns
ColorFilter

getCornerRadius

added in version 22.1.0
float getCornerRadius ()

Returns
float The corner radius applied when drawing the bitmap.

getGravity

added in version 22.1.0
int getGravity ()

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

Returns
int the gravity applied to the bitmap

See also:

getIntrinsicHeight

int getIntrinsicHeight ()

Returns
int

getIntrinsicWidth

int getIntrinsicWidth ()

Returns
int

getOpacity

added in version 22.1.0
int getOpacity ()

Returns
int

getPaint

added in version 22.1.0
Paint getPaint ()

Returns the paint used to render this drawable.

Returns
Paint

hasAntiAlias

added in version 22.1.0
boolean hasAntiAlias ()

Indicates whether anti-aliasing is enabled for this drawable.

Returns
boolean True if anti-aliasing is enabled, false otherwise.

hasMipMap

added in version 22.1.0
boolean hasMipMap ()

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

Returns
boolean True if the mipmap hint is set, false otherwise. If the bitmap is null, this method always returns false.

See also:

isCircular

added in version 24.1.0
boolean isCircular ()

Returns
boolean true if the image is circular, else false.

setAlpha

added in version 22.1.0
void setAlpha (int alpha)

Parameters
alpha int

setAntiAlias

added in version 22.1.0
void setAntiAlias (boolean aa)

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

added in version 24.1.0
void setCircular (boolean circular)

Sets the image shape to circular.

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

Parameters
circular boolean

setColorFilter

added in version 22.1.0
void setColorFilter (ColorFilter cf)

Parameters
cf ColorFilter

setCornerRadius

added in version 22.1.0
void setCornerRadius (float cornerRadius)

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

Parameters
cornerRadius float

setDither

added in version 26.1.0
void setDither (boolean dither)

Parameters
dither boolean

setFilterBitmap

void setFilterBitmap (boolean filter)

Parameters
filter boolean

setGravity

added in version 22.1.0
void setGravity (int gravity)

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

Parameters
gravity int: the gravity

See also:

setMipMap

added in version 22.1.0
void setMipMap (boolean mipMap)

Enables or disables the mipmap hint for this drawable's bitmap. See 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

added in version 22.1.0
void setTargetDensity (DisplayMetrics metrics)

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

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

setTargetDensity

added in version 22.1.0
void setTargetDensity (Canvas canvas)

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

added in version 22.1.0
void setTargetDensity (int density)

Set the density at which this drawable will be rendered.

Parameters
density int: The density scale for this drawable.

Protected methods

onBoundsChange

void onBoundsChange (Rect bounds)

Parameters
bounds Rect