An example of this paper is to analyze the anti aliasing method of Android programming drawing. Share to everyone for your reference, specific as follows:
When drawing, the picture, if rotated or scaled, will always appear in those gorgeous jagged. In fact, Android has its own way of dealing with it.
Method One: Add anti-aliasing mark to paint. The Paint object is then passed as an argument to the canvas drawing method.
Copy Code code as follows:
Paint.setantialias (TRUE);
Method Two: To add anti-aliasing mark to canvas.
Some places can not use paint, directly to canvas add anti-aliasing, more convenient.
Copy Code code as follows:
Canvas.setdrawfilter (New Paintflagsdrawfilter (0, Paint.anti_alias_flag| Paint.filter_bitmap_flag));
The test code is as follows:
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 {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);
}
}
The following illustration is an effect:
As can be seen, both methods are quite effective.
I hope this article will help you with the Android program.