Simple realization of the effect of frosted glass

Source: Internet
Author: User

The project needs to be applied to the effect of frosted glass. After searching, I stepped on some pits and found a temporary way.

The core of the control is the use of the Renderscript class, which belongs to the Jni class, in the lower version of the Android system, is not equipped with its related methods. So we can only use the class inside the SUPPORT.V8. However, SUPPORT.V8 is not placed in the new project by default, so we need to add it ourselves.

First step: Place the ARMEABI-V7A and x86 folders under the D:\AndroidSdk\build-tools\23.0.1\renderscript\lib\packaged directory in the Libs path of the project

  

Step two: Write a script in Build.gradle to compile these two. so files

    Task Nativelibstojar (Type:zip, Description: "Create a jar archive of the native Libs") {        destinationdir file ( "$projectDir/libs")        "NATIVE_LIBS2"        "jar"        "Libs", include: "**/*.so")         "Lib"    }    tasks.withtype (javacompile) {        - Compiletask.dependson ( Nativelibstojar)    }

Step Three: Rebuild Project

Fourth step: Add the jar package just compiled NATIVE_LIBS2

  

Fifth step: The method of wool glass effect

    Private void int radius) {        = renderscript.create (this);         = Allocation.createfrombitmap (rs, overlay);         = Scriptintrinsicblur.create (RS, overlayalloc.getelement ());        Blur.setinput (overlayalloc);        Blur.setradius (RADIUS);        Blur.foreach (overlayalloc);        Overlayalloc.copyto (overlay);        View.setbackground (new  bitmapdrawable (getresources (), overlay));        Rs.destroy ();    }

PS: In this method, radius is the granularity of the image blur. As we enter the Setradius method, we can see

     Public void Setradius (float  radius) {        if(Radius > 0.0F && radius <= 25.0F) {            this. SetVar (0, radius);          Else {            thrownew rsillegalargumentexception ("Radius Out of range (0 < R <= 25)." );        }    }

Radius max is 25.0

I suspect that in designing this method, developers also consider that this method is a relatively high degree of time complexity, especially in large images, the need for a large degree of ambiguity, there will be a great probability of performance problems, or even oom.

So, what if we need a more ambiguous situation than 25, or if there is a larger picture that needs to be blurred?

Commonly used methods, that is, the original need to blur the image first narrowed, then blurred, and then displayed. After a round of narrowing, the system will automatically integrate some pixel points into one, after blurring and amplification, the degree of ambiguity obtained will be higher than the degree of direct ambiguity.

done!

Simple realization of the effect of frosted glass

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.