Currently, in Android, I know that there are two kinds of sawtooth situations.
1) when we use a canvas to draw a bitmap, If we select a bitmap, the bitmap will appear at the same time.
2) When you use the rotateanimation of a view for animation, if the view contains a large number of images, the page will also be distorted.
We will consider these two situations separately.
1. Use canvas to draw a bit.
When using canvas to draw a bitmap, we generally use the drawbitmap function family. In these functions, there is a paint parameter. To prevent aliasing, we need to use this parameter.
First, you need to create a paint in your constructor.
Paint mpaint = new paint ()
Then, you need to set two parameters:
1) mpaint. setantialias ();
2) mpaint. setbitmapfilter (true ).
The first function is used to prevent the Sawtooth of the edge, and the second function is used to filter the bitmap. Finally, when drawing, call the drawbitmap function, you only need to pass the entire painting.
2. rotateanimation
Sometimes, when you create a rotateanimation, you will find that the nasty sawtooth appears again. At this time, because you cannot control the plotting of bitmap, you can only use other methods to prevent the aliasing. In addition, if you draw many bitmaps. You do not want to input a painting for each bitmap. In other cases, you cannot control the rendering of each window. You need to use the following method to process the entire canvas.
1) create a paint filter in your constructor.
Paintflagsdrawfilter msetfil = new paintflagsdrawfilter (0, paint. filter_bitmap_flag );
The first parameter is the flag you want to clear, and the second parameter is the flag you want to set. Filter bitmap.
2) When you are drawing a picture, if it is a view, it is in ondraw. If it is a viewgroup, the following function is called in dispatchdraw.
Canvas. setdrawfilter (msetfil );
3. drawable
Finally, in the drawable class and its sub-classes, the setfilterbitmap function can be used to filter bitmap. In this way, when you select drawable, it will have the anti-aliasing effect.