Android Anti-aliasing method [go]

Source: Internet
Author: User

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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.