Android中Bitmap位图的渲染与操作

2014-11-24 14:00:03 · 作者: · 浏览: 2

1.通过一张资源文件得到一个位图


Bitmap bmp = BitmapFactory.decodeResource(this.getResources(),R.drawable.icon);


2.绘制位图


canvas.drawBitmap(bmp,0,0,paint);


3.旋转位图


方法一:


canvas.save();


canvas.rotate(30,bmp.getWidth()/2,bmp.getHeight()/2);


canvas.drawBitmap(bmp,0,0,paint);


canvas.restore();


方法二:


Matrix mx = new Matrix();


mx.postRotate(30,bmp.getWidth()/2,bmp.getHeight()/2);


canvas.drawBitmap(bmp,0,0,paint);


4平移位图


方法一:


canvas.save();


canvas.translate(10,10);


canvas.drawBitmap(bmp,0,0,paint);


canvas.restore();


方法二:


Matrix mx = new Matrix();


mx.postTranslate(10,10);


canvas.drawBitmap(bmp,0,0,paint);