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);}}