Android的Android.graphics.Matrix类提供了图形变换的方法,如旋转,缩放,错切,平移等。
旋转变化:
setRotate()
postRotate()
preRotate()
setRotate(float degress)
SetRetate(float degress.float x.float,y)有旋转中心的旋转
缩放图形
setScale()
错切变换
setSkew()
平移变换:
SetTranslate(float x,float y)
用法:
Bitmap s = BitmapFactory.decodeResource(this.getResources(), R.mipmap.test);
Matrix matrix=new Matrix();
matrix.setRotate(45);
matrix.postRotate(30);//组合变换除第一个用set外,其他都用post
canvas.drawBitmap(s,matrix,paint);
使用BitmapShader进行图形裁剪
创建一个位图并加载要填充的对象
创建bitmapShader构造方法。用填充位图创建一个填充对象重复方式
Bitmap s = BitmapFactory.decodeResource(this.getResources(), R.mipmap.big);
BitmapShader shader=new BitmapShader(s, Shader.TileMode.MIRROR,Shader.TileMode.REPEAT);
paint.setShader(shader);
canvas.drawCircle(300,300,150,paint);
效果如下图所示