Android 4.0 above Blurmaskfilter effect is invalid

Source: Internet
Author: User

Basic use of Android Maskfilter:

the Maskfilter class can assign an edge effect to paint.
The maskfilter extension can apply transformations to an alpha channel on a paint edge. Android contains the following maskfilter:

blurmaskfilter specifies a blurred style and radius to handle the edges of the paint.
Embossmaskfilter Specifies the direction of the light source and ambient light intensity to add an embossed effect.

to apply a maskfilter, you can use the Setmaskfilter method and pass it to a Maskfilter object. The following example applies a embossmaskfilter to an already existing paint application:

the Fingerpaint API demo included in the SDK is a great example of how to use Maskfilter. It shows the effects of these two filter types.

But:

In Manifest.xml's

<USES-SDK
        android:minsdkversion= "8"
         android:targetsdkversion= "/>";

When the targetsdkversion is set to 14 or more, the blurmaskfilter will not work!

Fig. targetsdkversion= "8"                                                                                   figure II Targetsdkversion= " "

Demo Code:

Package Com.example.test;import Android.annotation.suppresslint;import Android.app.activity;import Android.content.context;import Android.graphics.bitmap;import Android.graphics.blurmaskfilter;import Android.graphics.blurmaskfilter.blur;import Android.graphics.canvas;import Android.graphics.color;import Android.graphics.paint;import Android.graphics.paint.style;import Android.graphics.path;import Android.graphics.rect;import Android.graphics.rectf;import Android.os.bundle;import Android.view.View;public class Canvas2activity extends Activity {@Overrideprotected void onCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (new Canvasview (This));} Class Canvasview extends View{paint Paint = null; Rect rect1 = null; Rect rect2 = null; Path path2 = null;public Canvasview (context context) {Super (context);p aint = new paint ();p aint.setflags (paint.anti_ Alias_flag);p Aint.setantialias (True);p Aint.setcolor (color.red);p aint.settextsize (;p aint.setstyle (Style.FILL _and_stRoke);p aint.setstrokewidth (3);p Aint.setsubpixeltext (true);  Blurmaskfilter BMF = new Blurmaskfilter (blur.solid);p aint.setmaskfilter (BMF), rect2 = new Rect (0, max);p ath2 = new Path ();p Ath2.moveto (ath2.quadto),;p Ath2.lineto (a),;p Ath2.close () (); @SuppressLint ("drawallocation") @Overrideprotected void OnDraw (canvas canvas) {//Paint color Canvas.drawargb (0x7F, 0x33, 0x66 , 0x99); Canvas.drawrect (rect2, paint); Canvas.drawpath (path2, paint); Super.ondraw (canvas);}}

Related Article

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.