Blur
自从iOS系统引入了Blur效果,也就是所谓的毛玻璃、模糊化效果,磨砂效果,各大系统就开始竞相模仿,这是一个怎样的效果呢,我们现来看一些图:
这些就是典型的Blur效果,在iOS和MIUI中还有很多,这里就不再贴图了。
实现
实现Blur效果主要有两种方式,一个是通过RenderScript来做,另一种是通过直接对像素点来进行算法处理。
RenderScript是API11之后才引入的,所以对版本有限制,而且RenderScript确实挺复杂的,虽然使用他的Blur功能很简单,但是要真正搞懂,不是一天两天的事。
本文主要介绍另一种算法来实现Blur,这个算法是目前市面上对Blur效果处理比较好的一种算法了,研究的前沿网址请戳 我是Blur 。
经典图:
有兴趣的朋友可以去看看。
使用
下面我们来看看如何在Android中来使用Blur,当然,我们需要使用上面提到的FastBlur
package com.xys.blur;import android.graphics.Bitmap;/** * Created by paveld on 3/6/14. */public class FastBlur { public static Bitmap doBlur(Bitmap sentBitmap, int radius, boolean canReuseInBitmap) { // Stack Blur v1.0 from // http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html // // Java Author: Mario Klingemann <mario at quasimondo.com> // http://incubator.quasimondo.com // created Feburary 29, 2004 // Android port : Yahel Bouaziz <yahel at kayenko.com> // http://www.kayenko.com // ported april 5th, 2012 // This is a compromise between Gaussian Blur and Box blur // It creates much better looking blurs than Box Blur, but is // 7x faster than my Gaussian Blur implementation. // // I called it Stack Blur because this describes best how this // filter works internally: it creates a kind of moving stack // of colors whilst scanning through the image. Thereby it // just has to add one new block of color to the right side // of the stack and remove the leftmost color. The remaining // colors on the topmost layer of the stack are either added on // or reduced by one, depending on if they are on the right or // on the left side of the stack. // // If you are using this algorithm in your code please add // the following line: // // Stack B