public class NinePatch extends Object
The Draw 9-Patch tool offers an extremely handy way to create your NinePatch images, using a WYSIWYG graphics editor.
Modifier and Type | Class and Description |
---|---|
static class |
NinePatch.InsetStruct
Struct of inset information attached to a 9 patch bitmap.
|
Modifier and Type | Field and Description |
---|---|
long |
mNativeChunk
Used by native code.
|
Constructor and Description |
---|
NinePatch(Bitmap bitmap,
byte[] chunk)
Create a drawable projection from a bitmap to nine patches.
|
NinePatch(Bitmap bitmap,
byte[] chunk,
String srcName)
Create a drawable projection from a bitmap to nine patches.
|
NinePatch(NinePatch patch) |
Modifier and Type | Method and Description |
---|---|
void |
draw(Canvas canvas,
Rect location)
Draws the NinePatch.
|
void |
draw(Canvas canvas,
RectF location)
Draws the NinePatch.
|
void |
draw(Canvas canvas,
Rect location,
Paint paint)
Draws the NinePatch.
|
protected void |
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
Bitmap |
getBitmap()
Returns the bitmap used to draw this NinePatch.
|
int |
getDensity()
Return the underlying bitmap's density, as per
Bitmap.getDensity() . |
int |
getHeight()
Returns the intrinsic height, in pixels, of this NinePatch.
|
String |
getName()
Returns the name of this NinePatch object if one was specified
when calling the constructor.
|
Paint |
getPaint()
Returns the paint used to draw this NinePatch.
|
Region |
getTransparentRegion(Rect bounds)
Returns a
Region representing the parts of the NinePatch that are
completely transparent. |
int |
getWidth()
Returns the intrinsic width, in pixels, of this NinePatch.
|
boolean |
hasAlpha()
Indicates whether this NinePatch contains transparent or translucent pixels.
|
static boolean |
isNinePatchChunk(byte[] chunk)
Verifies that the specified byte array is a valid 9-patch data chunk.
|
void |
setPaint(Paint p)
Sets the paint to use when drawing the NinePatch.
|
public long mNativeChunk
public NinePatch(Bitmap bitmap, byte[] chunk)
bitmap
- The bitmap describing the patches.chunk
- The 9-patch data chunk describing how the underlying bitmap
is split apart and drawn.public NinePatch(Bitmap bitmap, byte[] chunk, String srcName)
bitmap
- The bitmap describing the patches.chunk
- The 9-patch data chunk describing how the underlying
bitmap is split apart and drawn.srcName
- The name of the source for the bitmap. Might be null.public NinePatch(NinePatch patch)
protected void finalize() throws Throwable
Object
finalize
method to dispose of
system resources or to perform other cleanup.
The general contract of finalize
is that it is invoked
if and when the JavaTM virtual
machine has determined that there is no longer any
means by which this object can be accessed by any thread that has
not yet died, except as a result of an action taken by the
finalization of some other object or class which is ready to be
finalized. The finalize
method may take any action, including
making this object available again to other threads; the usual purpose
of finalize
, however, is to perform cleanup actions before
the object is irrevocably discarded. For example, the finalize method
for an object that represents an input/output connection might perform
explicit I/O transactions to break the connection before the object is
permanently discarded.
The finalize
method of class Object
performs no
special action; it simply returns normally. Subclasses of
Object
may override this definition.
The Java programming language does not guarantee which thread will
invoke the finalize
method for any given object. It is
guaranteed, however, that the thread that invokes finalize will not
be holding any user-visible synchronization locks when finalize is
invoked. If an uncaught exception is thrown by the finalize method,
the exception is ignored and finalization of that object terminates.
After the finalize
method has been invoked for an object, no
further action is taken until the Java virtual machine has again
determined that there is no longer any means by which this object can
be accessed by any thread that has not yet died, including possible
actions by other objects or classes which are ready to be finalized,
at which point the object may be discarded.
The finalize
method is never invoked more than once by a Java
virtual machine for any given object.
Any exception thrown by the finalize
method causes
the finalization of this object to be halted, but is otherwise
ignored.
public String getName()
public Paint getPaint()
setPaint(Paint)
,
draw(Canvas, Rect)
,
draw(Canvas, RectF)
public void setPaint(Paint p)
p
- The paint that will be used to draw this NinePatch.getPaint()
,
draw(Canvas, Rect)
,
draw(Canvas, RectF)
public Bitmap getBitmap()
public void draw(Canvas canvas, RectF location)
getPaint()
.canvas
- A container for the current matrix and clip used to draw the NinePatch.location
- Where to draw the NinePatch.public void draw(Canvas canvas, Rect location)
getPaint()
.canvas
- A container for the current matrix and clip used to draw the NinePatch.location
- Where to draw the NinePatch.public void draw(Canvas canvas, Rect location, Paint paint)
getPaint()
and use the specified paint instead.canvas
- A container for the current matrix and clip used to draw the NinePatch.location
- Where to draw the NinePatch.paint
- The Paint to draw through.public int getDensity()
Bitmap.getDensity()
.public int getWidth()
getBitmap()
.public int getHeight()
getBitmap()
.public final boolean hasAlpha()
getBitmap().hasAlpha()
on this
NinePatch.public final Region getTransparentRegion(Rect bounds)
Region
representing the parts of the NinePatch that are
completely transparent.bounds
- The location and size of the NinePatch.Region
holding the parts of the specified bounds
that are transparent.public static boolean isNinePatchChunk(byte[] chunk)
chunk
- A byte array representing a 9-patch data chunk.