Android APIs
public abstract class

RoundedBitmapDrawable

extends Drawable
java.lang.Object
   ↳ android.graphics.drawable.Drawable
     ↳ android.support.v4.graphics.drawable.RoundedBitmapDrawable

Class Overview

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)
Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha) and color filter (set via setColorFilter).
int getAlpha()
Gets the current alpha value for the drawable.
final Bitmap getBitmap()
Returns the bitmap used by this drawable to render.
ColorFilter getColorFilter()
Returns the current color filter, or null if none set.
float getCornerRadius()
int getGravity()
Get the gravity used to position/stretch the bitmap within its bounds.
int getIntrinsicHeight()
Return the intrinsic height of the underlying drawable object.
int getIntrinsicWidth()
Return the intrinsic width of the underlying drawable object.
int getOpacity()
Return the opacity/transparency of this Drawable.
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.
void setAlpha(int alpha)
Specify an alpha value for the drawable.
void setAntiAlias(boolean aa)
Enables or disables anti-aliasing for this drawable.
void setColorFilter(ColorFilter cf)
Specify an optional color filter for the drawable.
void setCornerRadius(float cornerRadius)
Sets the corner radius to be applied when drawing the bitmap.
void setDither(boolean dither)
Set to true to have the drawable dither its colors when drawn to a device with fewer than 8-bits per color component.
void setFilterBitmap(boolean filter)
Set to true to have the drawable filter its bitmap when scaled or rotated (for drawables that use bitmaps).
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(int density)
Set the density at which this drawable will be rendered.
void setTargetDensity(Canvas canvas)
Set the density scale at which this drawable will be rendered.
[Expand]
Inherited Methods
From class android.graphics.drawable.Drawable
From class java.lang.Object

Public Methods

public void draw (Canvas canvas)

Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha) and color filter (set via setColorFilter).

Parameters
canvas The canvas to draw into

public int getAlpha ()

Gets the current alpha value for the drawable. 0 means fully transparent, 255 means fully opaque. This method is implemented by Drawable subclasses and the value returned is specific to how that class treats alpha. The default return value is 255 if the class does not override this method to return a value specific to its use of alpha.

public final Bitmap getBitmap ()

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

public ColorFilter getColorFilter ()

Returns the current color filter, or null if none set.

Returns
  • the current color filter, or null if none set

public float getCornerRadius ()

Returns
  • The corner radius applied when drawing the bitmap.

public int getGravity ()

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

Returns
  • the gravity applied to the bitmap
See Also

public int getIntrinsicHeight ()

Return the intrinsic height of the underlying drawable object. Returns -1 if it has no intrinsic height, such as with a solid color.

public int getIntrinsicWidth ()

Return the intrinsic width of the underlying drawable object. Returns -1 if it has no intrinsic width, such as with a solid color.

public int getOpacity ()

Return the opacity/transparency of this Drawable. The returned value is one of the abstract format constants in PixelFormat: UNKNOWN, TRANSLUCENT, TRANSPARENT, or OPAQUE.

Generally a Drawable should be as conservative as possible with the value it returns. For example, if it contains multiple child drawables and only shows one of them at a time, if only one of the children is TRANSLUCENT and the others are OPAQUE then TRANSLUCENT should be returned. You can use the method resolveOpacity(int, int) to perform a standard reduction of two opacities to the appropriate single output.

Note that the returned value does not take into account a custom alpha or color filter that has been applied by the client through the setAlpha(int) or setColorFilter(ColorFilter) methods.

Returns
  • int The opacity class of the Drawable.

public final Paint getPaint ()

Returns the paint used to render this drawable.

public boolean hasAntiAlias ()

Indicates whether anti-aliasing is enabled for this drawable.

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

public boolean hasMipMap ()

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

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

public void setAlpha (int alpha)

Specify an alpha value for the drawable. 0 means fully transparent, and 255 means fully opaque.

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
aa True if the bitmap should be anti-aliased, false otherwise.
See Also

public void setColorFilter (ColorFilter cf)

Specify an optional color filter for the drawable. Pass null to remove any existing color filter.

Parameters
cf the color filter to apply, or null to remove the existing color filter

public void setCornerRadius (float cornerRadius)

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

public void setDither (boolean dither)

Set to true to have the drawable dither its colors when drawn to a device with fewer than 8-bits per color component. This can improve the look on those devices, but can also slow down the drawing a little.

public void setFilterBitmap (boolean filter)

Set to true to have the drawable filter its bitmap when scaled or rotated (for drawables that use bitmaps). If the drawable does not use bitmaps, this call is ignored. This can improve the look when scaled or rotated, but also slows down the drawing.

public void setGravity (int gravity)

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

Parameters
gravity the gravity
See Also

public 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 True if the bitmap should use mipmaps, false otherwise.
See Also

public void setTargetDensity (DisplayMetrics metrics)

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

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

public void setTargetDensity (int density)

Set the density at which this drawable will be rendered.

Parameters
density The density scale for this drawable.

public 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 The Canvas from which the density scale must be obtained.