Paint Class Introduction
Paint is a brush that draws text and graphics with it to set drawing information such as graphic colors, styles, and so on.
1. Graphic drawing
Setargb (int a,int r,int g,int b);
Sets the color of the drawing, a for transparency, and r,g,b for the color value.
Setalpha (int a);
Sets the transparency of the drawing drawing.
SetColor (int color);
Sets the color of the drawing, which is represented by a color value that includes transparency and RGB colors.
Setantialias (Boolean AA);
Setting whether to use anti-aliasing will consume large resources and will slow down drawing graphics.
Setdither (Boolean dither);
Setting whether to use image dithering will make the painted picture more smooth and full, the image clearer
Setfilterbitmap (Boolean filter);
If the key is set to true, the image will filter out the optimized operation of the bitmap image during animation, speeding up the display
Speed, this setting depends on the settings of dither and Xfermode
Setmaskfilter (Maskfilter maskfilter);
Set Maskfilter, you can use different maskfilter to achieve the effect of filters, such as filtering, stereo, etc.
Setcolorfilter (Colorfilter colorfilter);
Set the color filter to achieve a color-free transformation effect when drawing colors
Setpatheffect (Patheffect effect);
To set the effect of drawing a path, such as a point drawing line
Setshader (Shader Shader);
Set the image effect and use shader to draw a variety of gradient effects
Setshadowlayer (float radius, float dx,float dy,int color);
Sets the shadow layer below the graph, produces a shadow effect, radius is the angle of the shadow, DX and dy are the distance from the shadow on the x-axis and the y-axis, and color is the shade of the shadow
SetStyle (Paint.style Style);
Sets the style of the brush for Fill,fill_or_stroke, or STROKE
Setstrokecap (Paint.cap Cap);
When the brush style is stroke or fill_or_stroke, set the brush's graphic style, such as the circle style
Cap.round, or square style Cap.square
Setsrokejoin (Paint.join Join);
Set how the shapes are combined, such as smoothing effects, when drawing
Setstrokewidth (float width);
Sets the thickness of the brush when the brush style is stroke or fill_or_stroke
Setxfermode (Xfermode xfermode);
Sets the way in which graphics overlap, such as merging, intersection, or union, often used to create eraser effects
2. Text rendering
Setfakeboldtext (Boolean fakeboldtext);
Simulation to implement bold text, set in small font effect will be very poor
Setsubpixeltext (Boolean subpixeltext);
Setting this to True will help the text appear on the LCD screen
SetTextAlign (Paint.align Align);
Set the alignment direction of the drawing text
Settextscalex (float ScaleX);
Set the scale of the drawing text x axis to achieve the effect of text stretching
Settextsize (float textSize);
Set the font size for drawing text
Settextskewx (float skewx);
Set italic text, skewx to oblique radians
Settypeface (Typeface Typeface);
Set the typeface object, which is the font style, including bold, italic and serif, non-lined body, etc.
Setunderlinetext (Boolean underlinetext);
Set the underlined text effect
Setstrikethrutext (Boolean strikethrutext);
Set the effect with strikethrough
Implementation of emboss and shadow effects
The Paint.setmaskfilter method needs to be used. Set Maskfilter, you can use different maskfilter to achieve the effect of filters, such as filtering, stereo, etc.
Setmaskfilter (Maskfilter 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:
Public class mainactivity extends Activity { @Override protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); ImageView IV =NewImageView ( This); Setcontentview (iv); Bitmap originimg = Bitmapfactory.decoderesource (Getresources (), r.drawable.painter); Bitmap grayimg = Bitmap.createbitmap (Originimg.getwidth (), Originimg.getheight (), Bitmap.Config.ARGB_8888); Canvas Canvas =NewCanvas (GRAYIMG); Paint paint =NewPaint ();//colormatrix ColorMatrix = new ColorMatrix (); //colormatrix.setsaturation (0); //colormatrixcolorfilter colormatrixfilter = new Colormatrixcolorfilter (ColorMatrix); //paint.setcolorfilter (colormatrixfilter); float[] Direction =New float[]{1,1,1};//Set ambient light level floatLight =0.4F//Select the level of reflection to apply floatSpecular =6;//Apply a certain level of blur to mask floatBlur =3.5F Embossmaskfilter emboss=NewEmbossmaskfilter (Direction,light,specular,blur); Paint.setmaskfilter (Emboss); Canvas.drawbitmap (Originimg,0,0, paint);//grayimg = Addwatermark (grayimg, "Hello World", this);Iv.setimagebitmap (GRAYIMG); }
:
Look at the following using Blurmaskfilter:
The front one controls the width of the shadow, and the following parameter controls the shadow effect
Maskfilter = new Blurmaskfilter (ten, BlurMaskFilter.Blur.SOLID);
Just replace it with the Paint.setmaskfilter method.
:
Maskfilter is a paint alpha channel conversion, the effect is not very obvious and colorfilter is to each RGB channel application conversion, the previous blog has been introduced. All classes derived by Colorfilter will ignore the alpha channel when performing their conversions.
Introduction to the Android Paint class and settings for Emboss and shadow effects