很多时候我们深夜看些电影 偶尔会看些这样的。
充满马赛克的电影,当你云雨一番的时候,看着旁边的卫生纸的时候,有没有想安卓能不能实现类似这样的功能呢。
下面我就带大家来做这种模糊功能类似马赛克。
首先做这个之前,我们需要先找一张让人脸红的照片来给他打上马赛克。
下面我们就要辣手摧花了。
首先我们先把 一个高斯模糊 算法工具类 导入,置于这个算法是怎么算的,我不懂,你们也别浪费时间,反正也不搞不懂。
FastBlur.java
package com.example.gaosi;
import android.graphics.Bitmap;
/**
* 高斯模糊。图片背景变成毛玻璃
*/
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 Blur Algorithm by Mario Klingemann <mario@quasimondo.com>
Bitmap bitmap;
if (canReuseInBitmap) {
bitmap = sentBitmap;
} else {
bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
}
if (radius < 1) {
return (null);
}
int w = bitmap.getWidth();
int h = bitmap.getHeight();
int[] pix = new int[w * h];
bitmap.getPixels(pix, 0, w, 0, 0, w, h);
int wm = w - 1;
int hm = h - 1;
int wh = w * h;
int div