如下封装了一个绘制.9.png的函数:
- public void drawNinepath(Canvas c, int id, Rect r1){
- Bitmap bmp= BitmapFactory.decodeResource(getResources(), id);
- NinePatch patch = new NinePatch(bmp, bmp.getNinePatchChunk(), null);
- patch.draw(c, r1);
- }
- 参数:Canvas 绘制画布不用说了,id是图片的id,r1是一个Rect对象,决定绘制的位置和大小;
- protected void onDraw(Canvas c){
- super.onDraw(c);
- paint.setColor(cacheColor);
- drawNinepath(c, R.drawable.bar, new Rect(50,50,300,200));
- }