Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/android/graphics/NinePatch#pubctors) \| [Methods](https://developer.android.com/reference/android/graphics/NinePatch#pubmethods) \| [Protected Methods](https://developer.android.com/reference/android/graphics/NinePatch#promethods) \| [Inherited Methods](https://developer.android.com/reference/android/graphics/NinePatch#inhmethods)

# NinePatch

*** ** * ** ***

` public class NinePatch `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.graphics.NinePatch |

<br />

*** ** * ** ***

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](https://developer.android.com/guide/topics/graphics/2d-graphics#nine-patch) document.

The [Draw 9-Patch](https://developer.android.com/guide/developing/tools/draw9patch) tool offers an extremely handy way to create your NinePatch images, using a WYSIWYG graphics editor.

<br />

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/graphics/NinePatch#NinePatch(android.graphics.Bitmap,%20byte[])(https://developer.android.com/reference/android/graphics/Bitmap bitmap, byte[] chunk) ` Create a drawable projection from a bitmap to nine patches. |
| ` https://developer.android.com/reference/android/graphics/NinePatch#NinePatch(android.graphics.Bitmap,%20byte[],%20java.lang.String)(https://developer.android.com/reference/android/graphics/Bitmap bitmap, byte[] chunk, https://developer.android.com/reference/java/lang/String srcName) ` Create a drawable projection from a bitmap to nine patches. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/graphics/NinePatch#draw(android.graphics.Canvas,%20android.graphics.Rect,%20android.graphics.Paint)(https://developer.android.com/reference/android/graphics/Canvas canvas, https://developer.android.com/reference/android/graphics/Rect location, https://developer.android.com/reference/android/graphics/Paint paint) ` Draws the NinePatch. |
| ` void` | ` https://developer.android.com/reference/android/graphics/NinePatch#draw(android.graphics.Canvas,%20android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Canvas canvas, https://developer.android.com/reference/android/graphics/Rect location) ` Draws the NinePatch. |
| ` void` | ` https://developer.android.com/reference/android/graphics/NinePatch#draw(android.graphics.Canvas,%20android.graphics.RectF)(https://developer.android.com/reference/android/graphics/Canvas canvas, https://developer.android.com/reference/android/graphics/RectF location) ` Draws the NinePatch. |
| ` https://developer.android.com/reference/android/graphics/Bitmap` | ` https://developer.android.com/reference/android/graphics/NinePatch#getBitmap()() ` Returns the bitmap used to draw this NinePatch. |
| ` int` | ` https://developer.android.com/reference/android/graphics/NinePatch#getDensity()() ` Return the underlying bitmap's density, as per `https://developer.android.com/reference/android/graphics/Bitmap#getDensity()`. |
| ` int` | ` https://developer.android.com/reference/android/graphics/NinePatch#getHeight()() ` Returns the intrinsic height, in pixels, of this NinePatch. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/graphics/NinePatch#getName()() ` Returns the name of this NinePatch object if one was specified when calling the constructor. |
| ` https://developer.android.com/reference/android/graphics/Paint` | ` https://developer.android.com/reference/android/graphics/NinePatch#getPaint()() ` Returns the paint used to draw this NinePatch. |
| ` final https://developer.android.com/reference/android/graphics/Region` | ` https://developer.android.com/reference/android/graphics/NinePatch#getTransparentRegion(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect bounds) ` Returns a `https://developer.android.com/reference/android/graphics/Region` representing the parts of the NinePatch that are completely transparent. |
| ` int` | ` https://developer.android.com/reference/android/graphics/NinePatch#getWidth()() ` Returns the intrinsic width, in pixels, of this NinePatch. |
| ` final boolean` | ` https://developer.android.com/reference/android/graphics/NinePatch#hasAlpha()() ` Indicates whether this NinePatch contains transparent or translucent pixels. |
| ` static boolean` | ` https://developer.android.com/reference/android/graphics/NinePatch#isNinePatchChunk(byte[])(byte[] chunk) ` Verifies that the specified byte array is a valid 9-patch data chunk. |
| ` void` | ` https://developer.android.com/reference/android/graphics/NinePatch#setPaint(android.graphics.Paint)(https://developer.android.com/reference/android/graphics/Paint p) ` Sets the paint to use when drawing the NinePatch. |

| ### Protected methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/graphics/NinePatch#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Public constructors

### NinePatch

Added in [API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public NinePatch (Bitmap bitmap, 
                byte[] chunk)
```

Create a drawable projection from a bitmap to nine patches.

<br />

| Parameters ||
|---|---|
| `bitmap` | `Bitmap`: The bitmap describing the patches. <br /> |
| `chunk` | `byte`: The 9-patch data chunk describing how the underlying bitmap is split apart and drawn. <br /> |

### NinePatch

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public NinePatch (Bitmap bitmap, 
                byte[] chunk, 
                String srcName)
```

Create a drawable projection from a bitmap to nine patches.

<br />

| Parameters ||
|---|---|
| `bitmap` | `Bitmap`: The bitmap describing the patches. <br /> |
| `chunk` | `byte`: The 9-patch data chunk describing how the underlying bitmap is split apart and drawn. <br /> |
| `srcName` | `String`: The name of the source for the bitmap. Might be null. <br /> |

## Public methods

### draw

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void draw (Canvas canvas, 
                Rect location, 
                Paint paint)
```

Draws the NinePatch. This method will ignore the paint returned by `https://developer.android.com/reference/android/graphics/NinePatch#getPaint()` and use the specified paint instead.

<br />

| Parameters ||
|---|---|
| `canvas` | `Canvas`: A container for the current matrix and clip used to draw the NinePatch. <br /> |
| `location` | `Rect`: Where to draw the NinePatch. <br /> |
| `paint` | `Paint`: The Paint to draw through. <br /> |

### draw

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void draw (Canvas canvas, 
                Rect location)
```

Draws the NinePatch. This method will use the paint returned by `https://developer.android.com/reference/android/graphics/NinePatch#getPaint()`.

<br />

| Parameters ||
|---|---|
| `canvas` | `Canvas`: A container for the current matrix and clip used to draw the NinePatch. <br /> |
| `location` | `Rect`: Where to draw the NinePatch. <br /> |

### draw

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void draw (Canvas canvas, 
                RectF location)
```

Draws the NinePatch. This method will use the paint returned by `https://developer.android.com/reference/android/graphics/NinePatch#getPaint()`.

<br />

| Parameters ||
|---|---|
| `canvas` | `Canvas`: A container for the current matrix and clip used to draw the NinePatch. <br /> |
| `location` | `RectF`: Where to draw the NinePatch. <br /> |

### getBitmap

Added in [API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Bitmap getBitmap ()
```

Returns the bitmap used to draw this NinePatch.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap` | <br /> |

### getDensity

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getDensity ()
```

Return the underlying bitmap's density, as per `https://developer.android.com/reference/android/graphics/Bitmap#getDensity()`.

<br />

| Returns ||
|---|---|
| `int` | <br /> |

### getHeight

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getHeight ()
```

Returns the intrinsic height, in pixels, of this NinePatch. This is equivalent to querying the height of the underlying bitmap returned by `https://developer.android.com/reference/android/graphics/NinePatch#getBitmap()`.

<br />

| Returns ||
|---|---|
| `int` | <br /> |

### getName

Added in [API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String getName ()
```

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

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | <br /> |

### getPaint

Added in [API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Paint getPaint ()
```

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

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Paint` | <br /> |

**See also:**

- `https://developer.android.com/reference/android/graphics/NinePatch#setPaint(android.graphics.Paint)`
- `https://developer.android.com/reference/android/graphics/NinePatch#draw(android.graphics.Canvas,%20android.graphics.Rect)`
- `https://developer.android.com/reference/android/graphics/NinePatch#draw(android.graphics.Canvas,%20android.graphics.RectF)`

### getTransparentRegion

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final Region getTransparentRegion (Rect bounds)
```

Returns a `https://developer.android.com/reference/android/graphics/Region` representing the parts of the NinePatch that are completely transparent.

<br />

| Parameters ||
|---|---|
| `bounds` | `Rect`: The location and size of the NinePatch. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Region` | null if the NinePatch has no transparent region to report, else a `https://developer.android.com/reference/android/graphics/Region` holding the parts of the specified bounds that are transparent. <br /> |

### getWidth

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getWidth ()
```

Returns the intrinsic width, in pixels, of this NinePatch. This is equivalent to querying the width of the underlying bitmap returned by `https://developer.android.com/reference/android/graphics/NinePatch#getBitmap()`.

<br />

| Returns ||
|---|---|
| `int` | <br /> |

### hasAlpha

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final boolean hasAlpha ()
```

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

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

### isNinePatchChunk

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static boolean isNinePatchChunk (byte[] chunk)
```

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

<br />

| Parameters ||
|---|---|
| `chunk` | `byte`: A byte array representing a 9-patch data chunk. <br /> |

| Returns ||
|---|---|
| `boolean` | True if the specified byte array represents a 9-patch data chunk, false otherwise. <br /> |

### setPaint

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setPaint (Paint p)
```

Sets the paint to use when drawing the NinePatch.

<br />

| Parameters ||
|---|---|
| `p` | `Paint`: The paint that will be used to draw this NinePatch. <br /> |

**See also:**

- `https://developer.android.com/reference/android/graphics/NinePatch#getPaint()`
- `https://developer.android.com/reference/android/graphics/NinePatch#draw(android.graphics.Canvas,%20android.graphics.Rect)`
- `https://developer.android.com/reference/android/graphics/NinePatch#draw(android.graphics.Canvas,%20android.graphics.RectF)`

## Protected methods

### finalize

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void finalize ()
```

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the `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 Java 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.

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/Throwable` |   |