Android Shader color and Image Rendering

Source: Internet
Author: User

Android Shader color and Image Rendering

 

Shader

Shader is a base class that indicates the horizontal span of colors during painting.

Its subclass is embedded in the Paint and called the paint. setShader (shader ).

For objects other than Bitmap, the color is obtained from the shader when the Paint is used for painting.

 

Shader. TileMode rendering Mode

 

public enum TileMode {     CLAMP   (0),    REPEAT  (1),    MIRROR  (2);    TileMode(int nativeInt) {        this.nativeInt = nativeInt;    }    final int nativeInt;}
CLAMP: if it exceeds the bounds (bounds ),

 

 

REPEAT: REPEAT bitmap

MIRROR: REPEAT bitmap. If it is different from REPEAT, it is an image REPEAT, that is, a reverse REPEAT.

 

Shader subclass:

BitmapShader (android. graphics) Image Rendering
ComposeShader (android. graphics) combined Rendering
LinearGradient (android. graphics) linear Rendering
RadialGradient (android. graphics) ring Rendering
SweepGradient (android. graphics) scan Rendering

 

BitmapShader

New BitmapShader (bitmap, Shader. TileMode. REPEAT, Shader. TileMode. MIRROR); rendering images in a certain rendering Mode

 

ComposeShader

New ComposeShader (shaderA, shaderB, PorterDuff. Mode. DST); combines the two rendering effects and combines them with PorterDuff. Mode.

 

LinearGradient

New LinearGradient (0, 0, bitmap. getWidth (), bitmap. getHeight (), 0x470000ff, 0xefffff00, Shader. TileMode. CLAMP );

Linear changes between two colors in a certain rendering mode within a certain area

New LinearGradient (0, 0, bitmap. getWidth (), bitmap. getHeight (), new int [] {0xffabc777, 0x2300ff00, 0x470000ff, 0xefffff00}, new float [] {0.1f, 0.3f, 0.5f, 1.0f}, Shader. tileMode. CLAMP );

In a certain area, linear changes are made between a set of colors in a certain rendering mode. The position of the changes is determined by the float array. The length of the int array and float array must be the same.

 

RadialGradient

Perform ring rendering with vertices (x, y) and radius r.

New RadialGradient (w/2, h/2, Math. min (w, h)/2, 0xddff00f0, 0xffabc777, Shader. TileMode. REPEAT );

New RadialGradient (w/2, h/2, Math. min (w, h)/2, new int [] {0xddff0000, 0x2300ff00, 0x470000ff, 0xffabc777}, new float [] {0.1f, 0.3f, 0.5f, 1.0f}, Shader. tileMode. CLAMP );

 

SweepGradient

Scan and rendering with points (x, y)

New SweepGradient (w/2, h/2, 0xddff00f0, 0xffabc777 );

New SweepGradient (w, h, new int [] {0xffff0000, 0xff00ff00, 0xff0000ff, 0xffabc777, signature}, new float [] {0.2f, 0.4f, 0.6f, 0.75f, 1f });

 

PorterDuff. Mode

 

Canvas. drawBitmap (mDstB, 0, 0, paint); // draw the target paint. setXfermode (SModes[I]); // use modecanvas. drawBitmap (mSrcB, 0, 0, paint); // draw the source paint. setXfermode (null); // clear the mode

 

 

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.