According to Android developer docs :
Shader is the based class for objects that return horizontal spans of colors during drawing. A subclass of Shader is installed in a Paint calling paint.setShader(shader). After that any object (other than a bitmap) that is drawn with that paint will get its color(s) from the shader.
But I don't understand that definition. Could you guys please tell me what is shader in android in simple terms? Also, what is the meaning of "horizontal spans of colors"?
Thanks a lot.
A shader is a piece of code that is executed on the Graphics Processing Unit (GPU), usually found on a graphics card, to manipulate an image before it is drawn to the screen. Shaders allow for various kinds of rendering effect, ranging from adding an X-Ray view to adding cartoony outlines to rendering output.
There are several kinds of shaders, but two are commonly used to create graphics on the web: Vertex Shaders and Fragment (Pixel) Shaders. Vertex Shaders transform shape positions into 3D drawing coordinates. Fragment Shaders compute the renderings of a shape's colors and other attributes.
A vertex shader is a program executed on the graphics card's GPU which operates on each vertex individually. This facilitates we can write our own custom algorithm to work with the vertex's. Pixel Shaders: A pixel shader is a program executed on the graphics card's GPU during the rasterization process for each pixel.
A shader allows to define for a Paint object the content which should be drawn.
For example you can use a BitmapShader to define that a bitmap should be used to draw. This allows you for example to draw an image with rounded corners. Simply define a BitmapShader for your Paint object and use the drawRoundRect() method to draw a rectancle with rounded corners.
Other Shaders provided by the Android platform are LinearGradient, RadialGradient and SweepGradient for drawing color gradients.
To use a Shaders assign it to your Paint object via the setShader() method.
If the area which is filled is larger than the Shaders you can define via the Shader tile mode how the rest should be filled.
The Shader.TileMode.CLAMP constant defines that the edge corners should be used to fill the extra space.
The Shader.TileMode.MIRROR constant defines that the image is mirrored.
The Shader.TileMode.REPEAT defines that the image will be repeated.
Source: Vogella
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With