Android Paint class introduction and setting of relief and shadow effects

Source: Internet
Author: User

Android Paint class introduction and setting of relief and shadow effects
Paint class Introduction

Paint is the Paint brush. You can use it to set drawing information such as the color and style of the drawing text and image.

1. Drawing

SetARGB (int a, int r, int g, int B );

Set the color of the painting. a indicates transparency, r, g, and B indicates the color value.

SetAlpha (int );

Set the transparency of the drawing.

SetColor (int color );

Set the color of the painting, which is represented by the color value. The color value includes the transparency and RGB color.

SetAntiAlias (boolean aa );

Setting whether to use the anti-aliasing function consumes a large amount of resources and slows down the drawing speed.

SetDither (boolean dither );

Set whether to use image jitter processing to make the color of the image more smooth and full, and make the image clearer.

SetFilterBitmap (boolean filter );

If this parameter is set to true, the Bitmap image is filtered out during the animation to accelerate the display.

Speed. This setting item depends on dither and xfermode settings.

SetMaskFilter (MaskFilter maskfilter );

Set MaskFilter. Different maskfilters can be used to implement filter effects, such as filtering and stereo.

SetColorFilter (ColorFilter colorfilter );

Set the color filter to achieve the effect of color conversion when drawing the color.

SetPathEffect (PathEffect effect );

Set the effect of the draw path, such as drawing a line.

SetShader (Shader shader );

Set the image effect and use Shader to draw various gradient effects.

SetShadowLayer (float radius, float dx, float dy, int color );

Set the shadow layer under the image to produce the shadow effect. radius indicates the shadow angle. dx and dy indicate the distance between the shadow on the X and Y axes, and color indicates the shadow color.

SetStyle (Paint. Style style Style );

Set the paint brush style to FILL, FILL_OR_STROKE, or STROKE.

SetStrokeCap (Paint. Cap cap );

When the paint brush style is STROKE or FILL_OR_STROKE, set the image style of the brush, such as the circle style.

Cap. ROUND, or SQUARE style Cap. SQUARE

SetSrokeJoin (Paint. Join join );

Set the combination of various images during painting, such as smooth effects.

SetStrokeWidth (float width );

When the paint brush style is STROKE or FILL_OR_STROKE, set the width of the paint brush.

SetXfermode (Xfermode xfermode );

Sets the processing method when the image overlaps, such as merging, intersection or union, which is often used to make the eraser erasure effect.

2. Text Rendering

SetFakeBoldText (boolean fakeBoldText );

Simulate the implementation of bold text, the effect on small font will be very poor

SetSubpixelText (boolean subpixelText );

Setting this parameter to true will help display the text on the LCD screen.

SetTextAlign (Paint. Align align );

Set the alignment direction of the drawn text

SetTextScaleX (float scaleX );

You can set the scale ratio of the X axis of the drawn text to achieve the stretching effect of the text.

SetTextSize (float textSize );

Set the font size of the drawn text

SetTextSkewX (float skewX );

Set italic text. skewX is a skewed radian.

SetTypeface (Typeface typeface );

Set the Typeface object, that is, the font style, including bold, italic, and lined body, non-lined body, etc.

SetUnderlineText (boolean underlineText );

Set text effects with underscores

SetStrikeThruText (boolean strikeThruText );

Set effects with strikethrough

Implementation of relief and shadow effects

You need to use the Paint. setMaskFilter method. // Set the MaskFilter. Different maskfilters can be used to implement the filter effect, such as filtering and stereo.
SetMaskFilter (MaskFilter maskfilter );
The MaskFilter class can assign edge effects to the Paint.
The extension of MaskFilter can be applied to the alpha channel of a Paint edge. Android includes the following maskfilters:
BlurMaskFilter specifies a blur style and radius to process the Paint edge.
EmbossMaskFilter specifies the direction of the light source and the ambient light intensity to add relief effects.
To apply a MaskFilter, you can use the setMaskFilter method and pass it a MaskFilter object. The following example applies an EmbossMaskFilter to an existing Paint:

Public class MainActivity extends Activity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); ImageView iv = new ImageView (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 = new Canvas (grayImg); Paint paint = new Paint (); // ColorMatrix colorMatrix = new ColorMatrix (); // colorMatrix. setSaturation (0); // ColorMatrixColorFilter colorMatrixFilter = new ColorMatrixColorFilter (colorMatrix); // paint. setColorFilter (colorMatrixFilter); float [] direction = new float [] {1, 1, 1}; // set the environmental brightness float light = 0.4f; // select the reflection level float specular = 6 for the application; // apply a certain level of fuzzy float blur = 3.5f to the mask; EmbossMaskFilter emboss = new EmbossMaskFilter (direction, light, specular, blur); paint. setMaskFilter (emboss); canvas. drawBitmap (originImg, 0, 0, paint); // grayImg = addWaterMark (grayImg, "hello world", this); iv. setImageBitmap (grayImg );}

:

Then we can use BlurMaskFilter:
// The width of the previous shadow and the other parameter controls the shadow effect.
MaskFilter = new BlurMaskFilter (10, BlurMaskFilter. Blur. SOLID );
Use the Paint. setMaskFilter method to replace it.
:

MaskFilter is used to convert the alpha channel of a painting. The effect is not obvious, while ColorFilter is used to convert each RGB channel. This is already introduced in the previous blog. All classes derived from ColorFilter will ignore the alpha channel when performing their conversion.

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.