FileDocCategorySizeDatePackage
NinePatch.javaAPI DocAndroid 1.5 API4983Wed May 06 22:42:00 BST 2009android.graphics

NinePatch

public class NinePatch extends Object
The NinePatch class permits drawing a bitmap in nine sections. The four corners are unscaled; the four edges are scaled in one axis, and the middle is scaled in both axes. Normally, the middle is transparent so that the patch can provide a selection about a rectangle. 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.

Fields Summary
private final Rect
mRect
private final Bitmap
mBitmap
private final byte[]
mChunk
private Paint
mPaint
private String
mSrcName
Constructors Summary
public NinePatch(Bitmap bitmap, byte[] chunk, String srcName)
Create a drawable projection from a bitmap to nine patches.

param
bitmap The bitmap describing the patches.
param
chunk The 9-patch data chunk describing how the underlying bitmap is split apart and drawn.
param
srcName The name of the source for the bitmap. Might be null.

        mBitmap = bitmap;
        mChunk = chunk;
        mSrcName = srcName;
        validateNinePatchChunk(mBitmap.ni(), chunk);
    
public NinePatch(NinePatch patch)

hide

        mBitmap = patch.mBitmap;
        mChunk = patch.mChunk;
        mSrcName = patch.mSrcName;
        mPaint = new Paint(patch.mPaint);
        validateNinePatchChunk(mBitmap.ni(), mChunk);
    
Methods Summary
public voiddraw(Canvas canvas, RectF location)
Draw a bitmap to nine patches.

param
canvas A container for the current matrix and clip used to draw the bitmap.
param
location Where to draw the bitmap.

        nativeDraw(canvas.mNativeCanvas, location,
                   mBitmap.ni(), mChunk,
                   mPaint != null ? mPaint.mNativePaint : 0);
    
public voiddraw(Canvas canvas, Rect location)
Draw a bitmap to nine patches.

param
canvas A container for the current matrix and clip used to draw the bitmap.
param
location Where to draw the bitmap.

        nativeDraw(canvas.mNativeCanvas, location,
                   mBitmap.ni(), mChunk,
                   mPaint != null ? mPaint.mNativePaint : 0);
    
public voiddraw(Canvas canvas, Rect location, Paint paint)
Draw a bitmap to nine patches.

param
canvas A container for the current matrix and clip used to draw the bitmap.
param
location Where to draw the bitmap.
param
paint The Paint to draw through.

        nativeDraw(canvas.mNativeCanvas, location,
                   mBitmap.ni(), mChunk, paint != null ? paint.mNativePaint : 0);
    
public intgetHeight()

        return mBitmap.getHeight();
    
public final RegiongetTransparentRegion(Rect location)

        int r = nativeGetTransparentRegion(mBitmap.ni(), mChunk, location);
        return r != 0 ? new Region(r) : null;
    
public intgetWidth()

        return mBitmap.getWidth();
    
public final booleanhasAlpha()

        return mBitmap.hasAlpha();
    
public static native booleanisNinePatchChunk(byte[] chunk)

private static native voidnativeDraw(int canvas_instance, RectF loc, int bitmap_instance, byte[] c, int paint_instance_or_null)

private static native voidnativeDraw(int canvas_instance, Rect loc, int bitmap_instance, byte[] c, int paint_instance_or_null)

private static native intnativeGetTransparentRegion(int bitmap, byte[] chunk, Rect location)

public voidsetPaint(Paint p)

        mPaint = p;
    
private static native voidvalidateNinePatchChunk(int bitmap, byte[] chunk)