There seems to be no embossmaskfilter related articles on the Internet, so I studied him here.
Lee produced, reproduced please indicate the source.
First of all: on the internet to find someone said Maskfilter can not be used, that is, some effects can not be displayed, here to correct: because Android 4.0 or more systems will default on hardware acceleration (can be through the code canvas.ishardwareaccelerated ( ), because the hardware acceleration is not perfect, so that some effects can not be displayed properly, how to turn off hardware acceleration stamp: Click to open the link
OK, back to the point, first look at the source code:
public class Embossmaskfilter extends Maskfilter { /** * Create an emboss maskfilter * * @param direction array of 3 scalars [x, Y, z] specifying the direction of the light source * @param ambient 0...1 amount of AM Bient Light * @param specular coefficient-specular highlights (e.g. 8) * @param blurradius amount to blur Before applying lighting (e.g. 3) * @return The emboss maskfilter * * Public Embossmaskfilter (float [] direction, float ambient, float specular, float Blurradius) { if (Direction.length < 3) { throw new Arrayi Ndexoutofboundsexception (); } Native_instance = Nativeconstructor (direction, ambient, specular, Blurradius); } private static native int nativeconstructor (float[] direction, float ambient, float specular, float blurradius);}
The source code is also very simple, create an embossed filter, that is, specify the direction of the light source and ambient light intensity to add emboss effect.
See what the parameters mean:
Direction is a float array that defines an array of length 3 scalar [x, Y, z] to specify the direction of the light source
Ambient values from 0 to 1, which defines the background light or the surrounding light.
Specular defines the specular reflectance factor.
Blurradius the blur radius.
The following code sets the effect
float []direction = new float[]{10, ten, 10};float ambient = 0.5f;float Specular = 1;float Blurradius = 1; Embossmaskfilter filter = new Embossmaskfilter (direction, ambient, specular, Blurradius);p aint.setmaskfilter (filter);
Effect:
Modify the values of several parameters:
float ambient = 0.1f;float Specular = 5;float Blurradius = 5;
Effect:
Android Embossmaskfilter Embossed effect implementation