Android中Bitmap位图的渲染与操作

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);

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wywjyj.html