Matrix matrix = new Matrix();
matrix.setRotate(15);
canvas.drawBitmap(bmp, matrix, paint);
消除锯齿
paint.setAntiAlias(true);
指定圆心的旋转
matrix.setRotate(15,bmp.getWidth()/2,bmp.getHeight()/2);
----------------------------------------------------------
public class MainActivity extends Activity {
private ImageView iv_src;
private ImageView iv_dest;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv_src = (ImageView) findViewById(R.id.iv_src);
iv_src.setImageBitmap(BitmapFactory.decodeFile("/sdcard/tom.png"));
iv_dest = (ImageView) findViewById(R.id.iv_dest);
}
public void click(View view) {
Bitmap bitmap = BitmapFactory.decodeFile("/sdcard/tom.png");
Bitmap source = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), bitmap.getConfig());
Matrix matrix = new Matrix();
//旋转图片
//matrix.setRotate(30);
matrix.setRotate(30, bitmap.getWidth()/2, bitmap.getHeight()/2);
//设置位移
//matrix.setTranslate(1.5f,-10);
Bitmap baseBitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, false);
Canvas canvas = new Canvas(baseBitmap);
canvas.drawBitmap(bitmap, matrix, new Paint());
iv_dest.setImageBitmap(baseBitmap);
}
}
整理自ppt 和 源码