Added in API level 1

NinePatch

open class NinePatch
kotlin.Any
   ↳ android.graphics.NinePatch

The NinePatch class permits drawing a bitmap in nine or more sections. Essentially, it allows the creation of custom graphics that will scale the way that you define, when content added within the image exceeds the normal bounds of the graphic. For a thorough explanation of a NinePatch image, read the discussion in the 2D Graphics document.

The Draw 9-Patch tool offers an extremely handy way to create your NinePatch images, using a WYSIWYG graphics editor.

Summary

Public constructors
NinePatch(bitmap: Bitmap!, chunk: ByteArray!)

Create a drawable projection from a bitmap to nine patches.

NinePatch(bitmap: Bitmap!, chunk: ByteArray!, srcName: String!)

Create a drawable projection from a bitmap to nine patches.

Public methods
open Unit
draw(canvas: Canvas!, location: RectF!)

Draws the NinePatch.

open Unit
draw(canvas: Canvas!, location: Rect!)

Draws the NinePatch.

open Unit
draw(canvas: Canvas!, location: Rect!, paint: Paint!)

Draws the NinePatch.

open Bitmap!

Returns the bitmap used to draw this NinePatch.

open Int

Return the underlying bitmap's density, as per Bitmap.getDensity().

open Int

Returns the intrinsic height, in pixels, of this NinePatch.

open String!

Returns the name of this NinePatch object if one was specified when calling the constructor.

open Paint!

Returns the paint used to draw this NinePatch.

Region!

Returns a Region representing the parts of the NinePatch that are completely transparent.

open Int

Returns the intrinsic width, in pixels, of this NinePatch.

Boolean

Indicates whether this NinePatch contains transparent or translucent pixels.

open static Boolean

Verifies that the specified byte array is a valid 9-patch data chunk.

open Unit

Sets the paint to use when drawing the NinePatch.

Protected methods
open Unit

Public constructors

NinePatch

Added in API level 1
NinePatch(
    bitmap: Bitmap!,
    chunk: ByteArray!)

Create a drawable projection from a bitmap to nine patches.

Parameters
bitmap Bitmap!: The bitmap describing the patches.
chunk ByteArray!: The 9-patch data chunk describing how the underlying bitmap is split apart and drawn.

NinePatch

Added in API level 1
NinePatch(
    bitmap: Bitmap!,
    chunk: ByteArray!,
    srcName: String!)

Create a drawable projection from a bitmap to nine patches.

Parameters
bitmap Bitmap!: The bitmap describing the patches.
chunk ByteArray!: The 9-patch data chunk describing how the underlying bitmap is split apart and drawn.
srcName String!: The name of the source for the bitmap. Might be null.

Public methods

draw

Added in API level 1
open fun draw(
    canvas: Canvas!,
    location: RectF!
): Unit

Draws the NinePatch. This method will use the paint returned by getPaint().

Parameters
canvas Canvas!: A container for the current matrix and clip used to draw the NinePatch.
location RectF!: Where to draw the NinePatch.

draw

Added in API level 1
open fun draw(
    canvas: Canvas!,
    location: Rect!
): Unit

Draws the NinePatch. This method will use the paint returned by getPaint().

Parameters
canvas Canvas!: A container for the current matrix and clip used to draw the NinePatch.
location Rect!: Where to draw the NinePatch.

draw

Added in API level 1
open fun draw(
    canvas: Canvas!,
    location: Rect!,
    paint: Paint!
): Unit

Draws the NinePatch. This method will ignore the paint returned by getPaint() and use the specified paint instead.

Parameters
canvas Canvas!: A container for the current matrix and clip used to draw the NinePatch.
location Rect!: Where to draw the NinePatch.
paint Paint!: The Paint to draw through.

getBitmap

Added in API level 19
open fun getBitmap(): Bitmap!

Returns the bitmap used to draw this NinePatch.

getDensity

Added in API level 4
open fun getDensity(): Int

Return the underlying bitmap's density, as per Bitmap.getDensity().

getHeight

Added in API level 1
open fun getHeight(): Int

Returns the intrinsic height, in pixels, of this NinePatch. This is equivalent to querying the height of the underlying bitmap returned by getBitmap().

getName

Added in API level 19
open fun getName(): String!

Returns the name of this NinePatch object if one was specified when calling the constructor.

getPaint

Added in API level 19
open fun getPaint(): Paint!

Returns the paint used to draw this NinePatch. The paint can be null.

getTransparentRegion

Added in API level 1
fun getTransparentRegion(bounds: Rect!): Region!

Returns a Region representing the parts of the NinePatch that are completely transparent.

Parameters
bounds Rect!: The location and size of the NinePatch.
Return
Region! null if the NinePatch has no transparent region to report, else a Region holding the parts of the specified bounds that are transparent.

getWidth

Added in API level 1
open fun getWidth(): Int

Returns the intrinsic width, in pixels, of this NinePatch. This is equivalent to querying the width of the underlying bitmap returned by getBitmap().

hasAlpha

Added in API level 1
fun hasAlpha(): Boolean

Indicates whether this NinePatch contains transparent or translucent pixels. This is equivalent to calling getBitmap().hasAlpha() on this NinePatch.

isNinePatchChunk

Added in API level 1
open static fun isNinePatchChunk(chunk: ByteArray!): Boolean

Verifies that the specified byte array is a valid 9-patch data chunk.

Parameters
chunk ByteArray!: A byte array representing a 9-patch data chunk.
Return
Boolean True if the specified byte array represents a 9-patch data chunk, false otherwise.

setPaint

Added in API level 1
open fun setPaint(p: Paint!): Unit

Sets the paint to use when drawing the NinePatch.

Parameters
p Paint!: The paint that will be used to draw this NinePatch.

Protected methods

finalize

Added in API level 1
protected open fun finalize(): Unit
Exceptions
java.lang.Throwable the Exception raised by this method