public class BitmapDrawable extends Drawable
Bitmap
object.
It can be defined in an XML file with the <bitmap>
element. For more
information, see the guide to Drawable Resources.
Also see the Bitmap
class, which handles the management and
transformation of raw bitmap graphics, and should be used when drawing to a
Canvas
.
Drawable.Callback, Drawable.ConstantState
Constructor and Description |
---|
BitmapDrawable()
Deprecated.
Use
BitmapDrawable(Resources) to ensure
that the drawable has correctly set its target density. |
BitmapDrawable(Bitmap bitmap)
Deprecated.
Use
BitmapDrawable(Resources, Bitmap) to ensure
that the drawable has correctly set its target density. |
BitmapDrawable(InputStream is)
Deprecated.
Use
BitmapDrawable(Resources, java.io.InputStream) to ensure
that the drawable has correctly set its target density. |
BitmapDrawable(Resources res)
Create an empty drawable, setting initial target density based on
the display metrics of the resources.
|
BitmapDrawable(Resources res,
Bitmap bitmap)
Create drawable from a bitmap, setting initial target density based on
the display metrics of the resources.
|
BitmapDrawable(Resources res,
InputStream is)
Create a drawable by decoding a bitmap from the given input stream.
|
BitmapDrawable(Resources res,
String filepath)
Create a drawable by opening a given file path and decoding the bitmap.
|
BitmapDrawable(String filepath)
Deprecated.
Use
BitmapDrawable(Resources, String) to ensure
that the drawable has correctly set its target density. |
Modifier and Type | Method and Description |
---|---|
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).
|
Bitmap |
getBitmap()
Returns the bitmap used by this drawable to render.
|
int |
getChangingConfigurations()
Return a mask of the configuration parameters for which this drawable
may change, requiring that it be re-created.
|
Drawable.ConstantState |
getConstantState()
Return a
Drawable.ConstantState instance that holds the shared state of this Drawable. |
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.
|
Paint |
getPaint()
Returns the paint used to render this drawable.
|
Shader.TileMode |
getTileModeX()
Indicates the repeat behavior of this drawable on the X axis.
|
Shader.TileMode |
getTileModeY()
Indicates the repeat behavior of this drawable on the Y axis.
|
void |
inflate(Resources r,
XmlPullParser parser,
AttributeSet attrs)
Inflate this Drawable from an XML resource.
|
Drawable |
mutate()
A mutable BitmapDrawable still shares its Bitmap with any other Drawable
that comes from the same resource.
|
protected void |
onBoundsChange(Rect bounds)
Override this in your subclass to change appearance if you recognize the
specified state.
|
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 colorFilter for the drawable.
|
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 |
setTargetDensity(Canvas canvas)
Set the density scale at which this drawable will be rendered.
|
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 |
setTileModeX(Shader.TileMode mode)
Sets the repeat behavior of this drawable on the X axis.
|
void |
setTileModeXY(Shader.TileMode xmode,
Shader.TileMode ymode)
Sets the repeat behavior of this drawable on both axis.
|
void |
setTileModeY(Shader.TileMode mode)
Sets the repeat behavior of this drawable on the Y axis.
|
clearColorFilter, copyBounds, copyBounds, createFromPath, createFromResourceStream, createFromResourceStream, createFromStream, createFromXml, createFromXmlInner, getBounds, getCallback, getCurrent, getLayoutDirection, getLayoutInsets, getLevel, getMinimumHeight, getMinimumWidth, getPadding, getState, getTransparentRegion, invalidateSelf, isStateful, isVisible, jumpToCurrentState, onLevelChange, onStateChange, resolveOpacity, scheduleSelf, setBounds, setBounds, setCallback, setChangingConfigurations, setColorFilter, setLayoutDirection, setLevel, setState, setVisible, unscheduleSelf
@Deprecated public BitmapDrawable()
BitmapDrawable(Resources)
to ensure
that the drawable has correctly set its target density.public BitmapDrawable(Resources res)
@Deprecated public BitmapDrawable(Bitmap bitmap)
BitmapDrawable(Resources, Bitmap)
to ensure
that the drawable has correctly set its target density.public BitmapDrawable(Resources res, Bitmap bitmap)
@Deprecated public BitmapDrawable(String filepath)
BitmapDrawable(Resources, String)
to ensure
that the drawable has correctly set its target density.public BitmapDrawable(Resources res, String filepath)
@Deprecated public BitmapDrawable(InputStream is)
BitmapDrawable(Resources, java.io.InputStream)
to ensure
that the drawable has correctly set its target density.public BitmapDrawable(Resources res, InputStream is)
public final Paint getPaint()
public final Bitmap getBitmap()
public void setTargetDensity(Canvas canvas)
canvas
- The Canvas from which the density scale must be obtained.Bitmap.setDensity(int)
,
Bitmap.getDensity()
public void setTargetDensity(DisplayMetrics metrics)
metrics
- The DisplayMetrics indicating the density scale for this drawable.Bitmap.setDensity(int)
,
Bitmap.getDensity()
public void setTargetDensity(int density)
density
- The density scale for this drawable.Bitmap.setDensity(int)
,
Bitmap.getDensity()
public int getGravity()
public void setGravity(int gravity)
gravity
- the gravitypublic void setAntiAlias(boolean aa)
aa
- True if the bitmap should be anti-aliased, false otherwise.public void setFilterBitmap(boolean filter)
Drawable
setFilterBitmap
in class Drawable
public void setDither(boolean dither)
Drawable
public Shader.TileMode getTileModeX()
Shader.TileMode#CLAMP
if the bitmap does not repeat,
Shader.TileMode#REPEAT
or Shader.TileMode#MIRROR
otherwise.public Shader.TileMode getTileModeY()
Shader.TileMode#CLAMP
if the bitmap does not repeat,
Shader.TileMode#REPEAT
or Shader.TileMode#MIRROR
otherwise.public void setTileModeX(Shader.TileMode mode)
Shader.TileMode#REPEAT
or
Shader.TileMode#MIRROR
the bitmap can be repeated (or tiled) if the bitmap
is smaller than this drawable.mode
- The repeat mode for this drawable.setTileModeY(android.graphics.Shader.TileMode)
,
setTileModeXY(android.graphics.Shader.TileMode, android.graphics.Shader.TileMode)
public final void setTileModeY(Shader.TileMode mode)
Shader.TileMode#REPEAT
or
Shader.TileMode#MIRROR
the bitmap can be repeated (or tiled) if the bitmap
is smaller than this drawable.mode
- The repeat mode for this drawable.setTileModeX(android.graphics.Shader.TileMode)
,
setTileModeXY(android.graphics.Shader.TileMode, android.graphics.Shader.TileMode)
public void setTileModeXY(Shader.TileMode xmode, Shader.TileMode ymode)
Shader.TileMode#REPEAT
or
Shader.TileMode#MIRROR
the bitmap can be repeated (or tiled) if the bitmap
is smaller than this drawable.xmode
- The X repeat mode for this drawable.ymode
- The Y repeat mode for this drawable.setTileModeX(android.graphics.Shader.TileMode)
,
setTileModeY(android.graphics.Shader.TileMode)
public int getChangingConfigurations()
Drawable
Drawable.setChangingConfigurations(int)
or 0 by default. Subclasses
may extend this to or in the changing configurations of any other
drawables they hold.getChangingConfigurations
in class Drawable
Configuration
.Configuration
protected void onBoundsChange(Rect bounds)
Drawable
onBoundsChange
in class Drawable
public void draw(Canvas canvas)
Drawable
public void setAlpha(int alpha)
Drawable
public void setColorFilter(ColorFilter cf)
Drawable
setColorFilter
in class Drawable
public Drawable mutate()
mutate
in class Drawable
Drawable.ConstantState
,
Drawable.getConstantState()
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException
Drawable
inflate
in class Drawable
XmlPullParserException
IOException
public int getIntrinsicWidth()
Drawable
getIntrinsicWidth
in class Drawable
public int getIntrinsicHeight()
Drawable
getIntrinsicHeight
in class Drawable
public int getOpacity()
Drawable
PixelFormat
:
PixelFormat.UNKNOWN
,
PixelFormat.TRANSLUCENT
,
PixelFormat.TRANSPARENT
, or
PixelFormat.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 Drawable.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 Drawable.setAlpha(int)
or Drawable.setColorFilter(android.graphics.ColorFilter)
methods.
getOpacity
in class Drawable
PixelFormat
public final Drawable.ConstantState getConstantState()
Drawable
Drawable.ConstantState
instance that holds the shared state of this Drawable.
qgetConstantState
in class Drawable
Drawable.ConstantState
,
Drawable.mutate()