To draw NinePatch on canvas

code

protected NinePatchDrawable shadowLeft;
......
Bitmap image = BitmapFactory.decodeResource(context.getResources(),R.drawable.shadow_left); byte[] chunk= image.getNinePatchChunk(); shadowLeft=new NinePatchDrawable(context.getResources(), image, chunk, new Rect(), null);
shadowLeft.setBounds(sx, sy, ex, ey);
shadowLeft.draw(canvas);

 

Make sure that your ninepatch image has strech area in top and left edge,Or you'll get the following error:

Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1), thread 9184 (om.ai.imagemask) 

JNI WARNING: received null array           
in Landroid/graphics/NinePatch;.validateNinePatchChunk:(I[B)V (GetArrayLength)

posted @ 2012-09-19 13:23  Qiengo  阅读(723)  评论(0编辑  收藏  举报