RoundedBitmapDrawable

Added in 1.1.0

public abstract class RoundedBitmapDrawable extends Drawable


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

void
draw(@NonNull Canvas canvas)
int
final @Nullable Bitmap

Returns the bitmap used by this drawable to render.

ColorFilter
float
int

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

int
int
int

This method is deprecated.

final @NonNull Paint

Returns the paint used to render this drawable.

boolean

Indicates whether anti-aliasing is enabled for this drawable.

boolean

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

boolean
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
void
setCornerRadius(float cornerRadius)

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

void
setDither(boolean dither)

This method is deprecated.

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

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.

void

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

Protected methods

void

Inherited methods

From android.graphics.drawable.Drawable
void
boolean
void
final Rect
final void
copyBounds(Rect bounds)
static Drawable
static Drawable
createFromResourceStream(
    Resources res,
    TypedValue value,
    InputStream is,
    String srcName
)
static Drawable
static Drawable
static Drawable
createFromXmlInner(
    Resources r,
    XmlPullParser parser,
    AttributeSet attrs
)
final Rect
Drawable.Callback
int
Drawable.ConstantState
Drawable
Rect
void
int
final int
int
int
Insets
void
boolean
getPadding(Rect padding)
int[]
Region
boolean
void
void
boolean
boolean
boolean
boolean
final boolean
void
Drawable
boolean
onLayoutDirectionChanged(int layoutDirection)
boolean
onLevelChange(int level)
boolean
onStateChange(int[] state)
static int
resolveOpacity(int op1, int op2)
void
scheduleSelf(Runnable what, long when)
void
setAutoMirrored(boolean mirrored)
void
setBounds(int left, int top, int right, int bottom)
final void
void
void
setHotspot(float x, float y)
void
setHotspotBounds(int left, int top, int right, int bottom)
final boolean
setLayoutDirection(int layoutDirection)
final boolean
setLevel(int level)
boolean
setState(int[] stateSet)
void
setTint(int tintColor)
void
void
void
boolean
setVisible(boolean visible, boolean restart)
void

Public methods

draw

Added in 1.1.0
public void draw(@NonNull Canvas canvas)

getAlpha

public int getAlpha()

getBitmap

Added in 1.1.0
public final @Nullable Bitmap getBitmap()

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

getColorFilter

public ColorFilter getColorFilter()

getCornerRadius

Added in 1.1.0
public float getCornerRadius()
Returns
float

The corner radius applied when drawing the bitmap.

getGravity

Added in 1.1.0
public int getGravity()

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

Returns
int

the gravity applied to the bitmap

See also
Gravity

getIntrinsicHeight

public int getIntrinsicHeight()

getIntrinsicWidth

public int getIntrinsicWidth()

getOpacity

Added in 1.1.0
public int getOpacity()

getPaint

Added in 1.1.0
public final @NonNull Paint getPaint()

Returns the paint used to render this drawable.

hasAntiAlias

Added in 1.1.0
public boolean hasAntiAlias()

Indicates whether anti-aliasing is enabled for this drawable.

Returns
boolean

True if anti-aliasing is enabled, false otherwise.

See also
setAntiAlias

hasMipMap

Added in 1.1.0
public 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
setMipMap

isCircular

Added in 1.1.0
public boolean isCircular()
Returns
boolean

true if the image is circular, else false.

setAlpha

Added in 1.1.0
public void setAlpha(int alpha)

setAntiAlias

Added in 1.1.0
public 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
boolean aa

True if the bitmap should be anti-aliased, false otherwise.

See also
hasAntiAlias

setCircular

Added in 1.1.0
public void setCircular(boolean circular)

Sets the image shape to circular.

This overwrites any calls made to setCornerRadius so far.

setColorFilter

Added in 1.1.0
public void setColorFilter(ColorFilter cf)

setCornerRadius

Added in 1.1.0
public void setCornerRadius(float cornerRadius)

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

setDither

Added in 1.1.0
public void setDither(boolean dither)

setFilterBitmap

public void setFilterBitmap(boolean filter)

setGravity

Added in 1.1.0
public void setGravity(int gravity)

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

Parameters
int gravity

the gravity

See also
Gravity

setMipMap

Added in 1.1.0
public void setMipMap(boolean mipMap)

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

True if the bitmap should use mipmaps, false otherwise.

See also
hasMipMap

setTargetDensity

Added in 1.1.0
public void setTargetDensity(@NonNull 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
@NonNull Canvas canvas

The Canvas from which the density scale must be obtained.

setTargetDensity

Added in 1.1.0
public void setTargetDensity(int density)

Set the density at which this drawable will be rendered.

Parameters
int density

The density scale for this drawable.

setTargetDensity

Added in 1.1.0
public void setTargetDensity(@NonNull DisplayMetrics metrics)

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

Parameters
@NonNull DisplayMetrics metrics

The DisplayMetrics indicating the density scale for this drawable.

Protected methods

onBoundsChange

protected void onBoundsChange(@NonNull Rect bounds)