歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android中Bitmap位圖的渲染與操作

Android中Bitmap位圖的渲染與操作

日期:2017/3/1 10:27:32   编辑:Linux編程

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

Copyright © Linux教程網 All Rights Reserved