Are the guys getting better with PTSD? Severe symptoms are not recommended to look ~ click a thumbs-up can go 🤡🤡🤡

Why are we talking about this in the first place? I’m a big fan of Dota. The state of LGD before TI this year, and the final result is really disappointing. I just won a little contest before the fourth of July. It’s the same opponent ~ ~

How do you draw the HarmoneyOS national Flag? Check out the article Juejin or Github. The LinearShader is used in this paper. At that time a little knowledge of the finished, sent an article. After learning and demo, we have this article, recording the use of several shaders.

Here is the text

Shader Shader

LinearShader

This class allows you to define a linear shader.

LinearShader linearShader = new LinearShader(
                    new Point[]{new Point(0.0), new Point(component.getWidth() / 2f.0)}, 
                    new float[] {0f.1f},
                    new Color[]{Color.RED, Color.TRANSPARENT}, mTileMode 
            );
Copy the code

The above code defines a horizontal, half-width component coloring area that draws red -> transparent from left to right.

preview
CLAMP_TILEMODE MIRROR_TILEMODE REPEAT_TILEMODE

SweepShader

Scan shader. Imagine making pancakes, scraping clockwise. TileMode does not affect the shader.

// The first and second parameters are the center coordinates
SweepShader sweepShader = new SweepShader(component.getWidth() / 2f,
                    component.getHeight() / 2f.new Color[]{Color.RED, Color.TRANSPARENT},
                    new float[] {0f.1f});Copy the code
preview

RadialShader RadialShader

The shader shades outward from the center of the circle along the radius direction.

// The first parameter is the center of the circle and the second parameter is the radius
RadialShader radialShader = new RadialShader(
                    new Point(component.getWidth() / 2f, component.getHeight() / 2f),
                    component.getHeight() / 2f.new float[] {0f.1f},
                    new Color[]{new Color(Color.rgb(0xFF.0xFF.0x01)), Color.TRANSPARENT},
                    mTileMode
            );
Copy the code
preview
CLAMP_TILEMODE MIRROR_TILEMODE REPEAT_TILEMODE

PixelMapShader bitmap shader

Use the bitmap as the content of the shader.

PixelMap pixelMaps = PixelMapUtils.createPixelMapByResId(ResourceTable.Media_lgd, getContext()).get();
PixelMapHolder pixelMapHolder = new PixelMapHolder(pixelMaps);
// The second and third parameters are horizontal and vertical TileMode respectively. I can specify them separately, I don't want them to be the same, but I'm just being lazy
PixelMapShader pixelMapShader = new PixelMapShader(pixelMapHolder, mTileMode, mTileMode);
Copy the code

Look at this little LGD iconThe edge to the right of the small icon is a few pixels red, which is why the preview belowCLAMP_MODEThe right side of the center is displayed as a line.

preview
CLAMP_TILEMODE MIRROR_TILEMODE REPEAT_TILEMODE

GroupShader GroupShader

Combine two shaders freely. BlendMode, defined according to parameter three, handles the effects of both shaders

GroupShader groupShader = new GroupShader(sweepShader, radialShader, BlendMode.DST_IN);
Copy the code

Notice that the third parameter is passed aBlendMode. Do believeAndroidAll of them are familiar. To carry a figure, a filibuster-proof majority |

preview
CLAMP_TILEMODE MIRROR_TILEMODE REPEAT_TILEMODE

Demo combines SweepShader and RadialShader,

NewStops (newPositions) & newColors

The first three shader constructors all pass in a float[] and Color[] parameter.

NewStops (newPositions)

The float array defines the position of the ShaderColor (ShaderColor) defined in newColors in the shader. This parameter can be null so that the defined newColors will be drawn evenly.

// There are two names for the same function in API. ❌ bad review

newColors

The Color array defines the shader Color

TileMode

How to draw the national flag head of HarmoneyOS on National Day? Juejin or dead simple. It mentions the use of these patterns

The DEMO address

AvatarDemoFor101

All of the above code in lice/DifferentShaderAbilitySlice. Java file.

Last

If you don’t write well, you can enjoy it. If you really want to learn technology, you still have to read the official documentation (// the official website is also quite uncomfortable).

Workmates. ‘

In addition, I missed the first seven posts of this article. Sorry I didn’t get a buff for the guys who read the article. 🤕