Android Embossmaskfilter Embossed effect implementation

Source: Internet
Author: User

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

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.