Mobile UI design increasingly popular Gaussian blur (Gaussian Blur) and frosted glass effect (scrub effect), how to use Android Renderscript simple implementation?

Source: Internet
Author: User

Gaussian Blur (Gaussian Blur) and frosted glass effects (also known as scrub effects) have become more popular in mobile UI design for the last two years, especially on iOS phones, and the iOS system also provides APIs to help developers achieve both of these effects in minutes. And the Android system has gone through a long process of exploration, the processing of pictures, from Java algorithm to the implementation of the NDK, a variety of groping endless.

Thankfully,Google has finally introduced Renderscript in API 11, a powerful picture-processing framework that helps Android developers focus on image processing algorithms rather than API scheduling. Using Renderscript for picture processing, you also need to understand Renderscript intrinsics, some of the operation classes that can help renderscript quickly implement various image processing. For example, Scriptintrinsicblur can help us to achieve the Gaussian blur effect simply and efficiently:

Public Bitmap Blurbitmap (Bitmap Bitmap) {//let ' s create a empty Bitmap with the same size of the Bitmap we want to blurbit Map Outbitmap = Bitmap.createbitmap (Bitmap.getwidth (), Bitmap.getheight (), config.argb_8888);//Instantiate a new Renderscriptrenderscript rs = renderscript.create (Getapplicationcontext ());//create an intrinsic Blur Script using the Renderscriptscriptintrinsicblur Blurscript = scriptintrinsicblur.create (RS, Element.u8_4 (RS));//Create the Allocations (In/out) with the Renderscript and the in/out bitmapsallocation Allin = Allocation.createfrombitmap (rs, bitmap ); Allocation Allout = Allocation.createfrombitmap (RS, Outbitmap)//set the radius of the blur:0 < radius <= 25BLURSCR Ipt.setradius (25.0f);//perform the Renderscriptblurscript.setinput (Allin); Blurscript.foreach (allOut);//Copy the Final bitmap created by the off Allocation to the Outbitmapallout.copyto (OUTBITMAP);//recycle the original bitmapbitmap.re Cycle ();//after finishing everything, we destroy the RenderScript.rs.destroy (); return outbitmap;} 

By setting the size of the blur radius (RADIUS) to control the sharpness of the image, a short line of code easily implements the Gaussian blur of the image, and we look at the image blur effect when radius equals the maximum value of 25:

Original effect:

Gaussian Blur:

Note: The Scriptintrinsicblur method only supports API 17 and later versions of the system, in order to be compatible with the old version,Google For the SUPPORT.V8 package, when using the Renderscript and Intrinsics classes, the related classes in the V8 package can be introduced:

import android.support.v8.renderscript.Allocation;import android.support.v8.renderscript.Element;import android.support.v8.renderscript.RenderScript;import android.support.v8.renderscript.ScriptIntrinsicBlur;

Also, in the Defaultconfig configuration of the App/build.gradle file, add the following two lines of content:

defaultConfig {......renderscriptTargetApi 19renderscriptSupportModeEnabled  true}

The ingenious use of Gaussian blur in design can often achieve unexpected experience, such as the great God Daimajia using Renderscript and Nineoldandroids to do a more creative UI interaction, open Source Library: Androidviewhover , the effect is as follows, interested students can explore:

written at the end :forFreedom | Knowledge should be open to access, look at the outside world, and it this line, not to go to Google data, finally, Amway a V--PN agent. a red apricot VPN, to Google to check the information is the absolute first choice, the connection speed, the use is also convenient. I bought is 99¥ a year, through this link (http://my.yizhihongxing.com/aff.php?aff=2509) registered after the Member center to lose the coupon code, split down, only 7 yuan per month, special benefits.

This document tags : Android Gaussian blur (frosted glass/matte) Mobile UI design renderscript Scriptintrinsicblur

Turn from SUN's BLOG-focus on Internet knowledge, share the spirit of the Internet!

The original address: "Mobile UI design increasingly popular Gaussian blur (Gaussian Blur) and frosted glass effect (matte effect), how to use Android Renderscript simple implementation?" 》

related reading:"Aaron swartz– Internet Genius to open the life course: every moment asked himself, now the world what is the most important thing I can participate in doing?" "
Related reading: " site environment Apache + PHP + mysql xampp, how to implement a server on the configuration of multiple sites?" "

Related reading: What is the engineer culture? Why are the engineers alive? Why do I need an engineer culture as an IT or internet company? "

Related reading: useful for programmers: 2017 latest in Google's Hosts file download and summary of the various hosts encountered the problem of the solution and configuration of the detailed

Related reading: the Spring Festival will come, and to the performance of the year-end award of the time! Programmer Performance KPI How do you calculate this long history puzzle? "

Related blog:SUN ' S blog -Focus on Internet knowledge and share the spirit of Internet! Go and see:www.whosmall.com

Mobile UI design increasingly popular Gaussian blur (Gaussian Blur) and frosted glass effect (scrub effect), how to use Android Renderscript simple implementation?

Related Article

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.