android 圖片旋轉 反鋸齒
阿新 • • 發佈:2019-01-29
- import android.content.Context;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.graphics.Canvas;
- import android.graphics.Matrix;
- import android.graphics.Paint;
- import android.graphics.PaintFlagsDrawFilter;
- import android.view.View;
- public class MyView extends View {
- private PaintFlagsDrawFilter pfd;
- private Paint mPaint = new Paint();
- private Matrix matrix = new Matrix();;
- private Bitmap bmp;
- public MyView(Context context) {
- super(context);
- initialize();
- }
- private void initialize() {
- pfd = new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG);
- mPaint.setAntiAlias(true);
- matrix.setRotate(30);
- matrix.postScale(0.5f, 0.5f);
- bmp = BitmapFactory.decodeResource(getResources(), R.drawable.show);
- }
- @Override
- public void dispatchDraw(Canvas canvas) {
- canvas.translate(100, 0);
- canvas.drawBitmap(bmp, matrix, null);
- canvas.translate(0, 250);
- canvas.drawBitmap(bmp, matrix, mPaint);
- canvas.setDrawFilter(pfd);
- canvas.translate(0, 250);
- canvas.drawBitmap(bmp, matrix, null);
- }
- }