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