Android Shader color, image rendering

Source: Internet
Author: User



Shader

Shader is a base class that represents the horizontal span of a color during drawing

Its subclasses are embedded in the paint to be used, calling Paint.setshader (shader).

Other than bitmap, colors are obtained from shader when drawing with the paint


Shader.tilemode Rendering Mode

public enum Tilemode {     CLAMP   (0),    REPEAT  (1),    MIRROR  (2);    Tilemode (int nativeint) {        this.nativeint = nativeint;    }    final int nativeint;}
CLAMP: If the original bounds (that is, the border of the artwork) is exceeded, the color on the repeating edge

REPEAT: Repeat Bitmap

MIRROR: Repeat bitmap, unlike repeat, it is a mirror repetition, namely: reverse repetition


Shader sub-class:

Bitmapshader (android.graphics) Image rendering
Composeshader (android.graphics) combo 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); Render an image in a rendering mode


Composeshader

New Composeshader (Shadera, Shaderb, PorterDuff.Mode.DST); Combine two rendering effects to Porterduff.mode


LinearGradient

New LinearGradient (0, 0, bitmap.getwidth (), Bitmap.getheight (), 0x470000ff,0xefffff00, Shader.TileMode.CLAMP);

Linear variation between two colors within a certain area, in a certain rendering mode

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, in a certain rendering mode, a set of color between the linear change, the position of change is determined by the float array. requires an array of int and float, consistent in length

Radialgradient

Ring rendering with dots (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.1 F, 0.3f, 0.5f, 1.0f}, Shader.TileMode.CLAMP);


Sweepgradient

Scan rendering with dots (x, y)

New Sweepgradient (W/2, H/2, 0xddff00f0, 0xffabc777);

New Sweepgradient (W, H, New int[]{0xffff0000, 0xff00ff00, 0xff0000ff, 0xffabc777, 0xffee00ee}, New float[]{0.2f, 0.4f, 0.6 F, 0.75f, 1f});


Porterduff.mode


canvas . Drawbitmap (mdstb   0   0   paint) ;//draw the target first  Paint.setxfermode (  smodes   [i]) ;//use mode  canvas . Drawbitmap (MSRCB   0   0   paint) ;//Redraw source  paint.setxfermode (null ) ;//clear mode  

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Shader color, image rendering

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.