9patch生成图片

private Bitmap get_ninepatch(int id,int x, int y, Context context){
// id is a resource id for a valid ninepatch

Bitmap bitmap = BitmapFactory.decodeResource(
context.getResources(), id);

byte[] chunk = bitmap.getNinePatchChunk();
NinePatchDrawable np_drawable = new NinePatchDrawable(bitmap,
chunk, new Rect(), null);
np_drawable.setBounds(0, 0,x, y);

Bitmap output_bitmap = Bitmap.createBitmap(x, y, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output_bitmap);
np_drawable.draw(canvas);

return output_bitmap;
}
posted @ 2015-06-04 17:47  齐永强2012  阅读(399)  评论(0编辑  收藏  举报