In Android, for now, I know there are two kinds of jagged situations.
① when we draw a bitmap with canvas, if we select the bitmap, the bitmap will appear jagged.
② in the view of the Rotateanimation animation, if the view contains a large number of graphics, will also appear jagged. We consider these two cases separately.
The case of drawing bits with canvas. When drawing bitmaps with canvas, generally, we use the Drawbitmap function family, in which there is a paint parameter, to prevent aliasing, we need to use this parameter. As follows: First in your constructor, you need to create a paint. 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 jagged edges, and the second function is used to filter the bitmap. Finally, when drawing, call the Drawbitmap function, just pass the entire paint in.
Sometimes, when you do rotateanimation, you will find that the nasty sawtooth appears again. This time, because you can't control the bitmap drawing, you can only use other methods to achieve anti-aliasing. Also, if you draw a lot of bitmaps. Do not want each bitmap to be drawn in a single paint. There are times when you can't control the drawing of each window, and you need to do it the following way-to handle the entire canvas.
1) in your constructor, create a paint filter. Paintflagsdrawfilter Msetfil = new Paintflagsdrawfilter (0, Paint.filter_bitmap_flag); The first parameter is the flag bit you want to clear, and the second parameter is the flag bit you want to set. Set here to filter the bitmap.
2) When you are drawing, if the view is in OnDraw, if it is ViewGroup then call the following function in Dispatchdraw. Canvas.setdrawfilter (Msetfil); ★ Finally, in addition, in the Drawable class and its subclasses, there is also a function setfilterbitmap can be used to filter the bitmap, so that when you choose Drawable, there will be anti-aliasing effect.
Android Anti-aliasing method [go]