This is found on the internet, but forgot where to find, after a lot of comparative testing, found this method will not oom, so far I have never met, today to find this previously established works, recorded:
First to show you the effect of the picture:
public class Fastblur {public static Bitmap Doblur (Bitmap sentbitmap, int radius, Boolean canreuseinbitmap) {//the IS A compromise between Gaussian Blur and Box Blur//This is a compromise between Gaussian blur and square blur products//It creates much better looking blurs than Box B
Lur, but is//he not only looks better than a square blur, but also realizes faster than Gaussian blur 7x faster than my Gaussian Blur.
I called it stack Blur because this describes the best how to this//I call him stack blur, because he illustrates how filters work in memory. Filter works Internally:it creates a kind of moving stack//of colors whilst scanning through the image.
thereby it//he realizes the scan of the picture while moving the color stack.
Just has to add one new blocks of color to the right side//In fact, it just adds a fresh color block on the right-hand side of the stack, and then removes the leftmost color. The stack and remove the leftmost color.
The remaining///the remaining color blocks of the stack's topmost modules are determined by whether they are in the stack to the right or to the left, to add or remove//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 the using this algorithm in your CODe please add//The following line://If you use this algorithm in your code, add the following lines/Stack Blur algorithm by Mario Klingemann <mario@quas
imondo.com>//Stack fuzzy algorithm is created by Mario Klingemann <mario@quasimondo.com> Bitmap Bitmap;
if (canreuseinbitmap) {bitmap = Sentbitmap;} else {//determines the storage of the pixel of the picture, that is, the bit-depth parameter of the picture's properties when viewed with the picture viewer.
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 = radius + radius + 1;
int r[] = new INT[WH];
int g[] = new INT[WH];
int b[] = new INT[WH];
int rsum, gsum, Bsum, x, Y, I, p, yp, Yi, yw;
int vmin[] = new Int[math.max (W, h)];
int divsum = (div + 1) >> 1;
Divsum *= divsum;
int dv[] = new int[256 * Divsum];
for (i = 0; i < 256 * divsum. i++) {Dv[i] = (i/divsum);} yw = Yi = 0;
int[][] stack = new INT[DIV][3];
int stackpointer;
int Stackstart;
Int[] Sir; int RBS;
int r1 = radius + 1;
int routsum, goutsum, boutsum;
int rinsum, ginsum, binsum; for (y = 0; y < h; y++) {rinsum = Ginsum = Binsum = Routsum = Goutsum = Boutsum = Rsum = gsum = bsum = 0; for (i =-ra Dius I <= radius; i++) {p = pix[yi + math.min (WM, Math.max (i, 0))]; sir = stack[i + radius]; sir[0] = (P & 0xff0000) >> sir[1
= (P & 0x00ff00) >> 8;
SIR[2] = (P & 0x0000ff);
RBS = R1-math.abs (i);
Rsum + = sir[0] * RBS;
Gsum + = sir[1] * RBS;
Bsum + = sir[2] * RBS; if (i > 0) {rinsum + = sir[0]; Ginsum + = sir[1]; Binsum + = sir[2];} else {routsum = sir[0]; goutsum = sir[1]; bouts
Um + = sir[2];
} stackpointer = radius; for (x = 0; x < W; x + +) {R[yi] = Dv[rsum]; G[yi] = Dv[gsum]; B[yi] = dv[bsum]; rsum = routsum; gsum-= Goutsum; bsum
-= Boutsum;
Stackstart = Stackpointer-radius + div;
sir = Stack[stackstart% div];
Routsum-= sir[0];
Goutsum-= sir[1];
Boutsum-= sir[2]; if (y = = 0) {Vmin[x] = math.min (x + radius + 1, WM);} p = pix[yw + VMIN[X]];
Sir[0] = (P & 0xff0000) >> 16;
SIR[1] = (P & 0x00ff00) >> 8;
SIR[2] = (P & 0x0000ff);
Rinsum + = sir[0];
Ginsum + = sir[1];
Binsum + = sir[2];
Rsum + = Rinsum;
Gsum + = Ginsum;
Bsum + = Binsum;
Stackpointer = (stackpointer + 1)% Div;
sir = stack[(stackpointer)% div];
Routsum + = sir[0];
Goutsum + = sir[1];
Boutsum + = sir[2];
Rinsum-= sir[0];
Ginsum-= sir[1];
Binsum-= sir[2];
yi++;
} yw + = W; for (x = 0; x < W x + +) {rinsum = Ginsum = Binsum = Routsum = Goutsum = Boutsum = Rsum = gsum = bsum = 0; YP =-radi
US * W; for (i =-radius i <= radius; i++) {Yi = Math.max (0, YP) + x; sir = stack[i + radius]; sir[0] = R[yi]; sir[1] = G[yi]
;
SIR[2] = B[yi];
RBS = R1-math.abs (i);
Rsum + = r[yi] * RBS;
Gsum + = g[yi] * RBS;
Bsum + = b[yi] * RBS; if (i > 0) {rinsum + = sir[0]; Ginsum + = sir[1]; Binsum + = sir[2];} else {routsum = sir[0]; goutsum = sir[1]; bouts
Um + = sir[2];
if (I < HM) {YP + = W;}}
Yi = x;
Stackpointer = radius; for (y = 0; y < h; y++) {//Preserve alpha channel: (0xff000000 & Pix[yi]) pix[yi] = (0xff000000 & pix[yi)) | (Dv[rsum] << 16) | (Dv[gsum] << 8) |
Dv[bsum];
Rsum-= routsum;
Gsum-= goutsum;
Bsum-= boutsum;
Stackstart = Stackpointer-radius + div;
sir = Stack[stackstart% div];
Routsum-= sir[0];
Goutsum-= sir[1];
Boutsum-= sir[2];
if (x = = 0) {Vmin[y] = math.min (y + r1, HM) * W;} p = x + vmin[y];
Sir[0] = r[p];
SIR[1] = g[p];
SIR[2] = b[p];
Rinsum + = sir[0];
Ginsum + = sir[1];
Binsum + = sir[2];
Rsum + = Rinsum;
Gsum + = Ginsum;
Bsum + = Binsum;
Stackpointer = (stackpointer + 1)% Div;
sir = Stack[stackpointer];
Routsum + = sir[0];
Goutsum + = sir[1];
Boutsum + = sir[2];
Rinsum-= sir[0];
Ginsum-= sir[1];
Binsum-= sir[2];
Yi + W;
} bitmap.setpixels (pix, 0, W, 0, 0, W, h);
return (bitmap); } The public class Mainactivity extends Appcompatactivity {//This method does not oom * * in Addonpredrawlistener to invoke Blur method to be able to
Gets the size of the control, controlling the degree of blur by Scalefactor and radius two parameters. * * * */@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_
Main);
Final ImageView ImageView = (imageview) Findviewbyid (r.id.img);
Final Bitmap Bitmap = Bitmapfactory.decoderesource (Getresources (), r.drawable.back1); Imageview.getviewtreeobserver (). Addonpredrawlistener (New Viewtreeobserver.onpredrawlistener () {@Override public
Boolean Onpredraw () {blur (bitmap, ImageView); return true;}}); } private void Blur (Bitmap bkg, view view) {Long Startms = System.currenttimemillis (); float scalefactor = 8; float Radiu
s = 20; Bitmap overlay = Bitmap.createbitmap ((int) (View.getmeasuredwidth ()/Scalefactor), (int) (View.getmeasuredheight ()/SC
Alefactor), Bitmap.Config.ARGB_8888);
Canvas Canvas = new Canvas (overlay);
Canvas.translate (-view.getleft ()/Scalefactor,-view.gettop ()/scalefactor);
Canvas.scale (1/scalefactor, 1/scalefactor);
Paint Paint = new Paint ();
Paint.setflags (Paint.filter_bitmap_flag); Canvas.drawbitmap (bkg, 0, 0, Paint);
Overlay = Fastblur.doblur (overlay, (int) radius, true);
View.setbackground (New Bitmapdrawable (Getresources (), overlay)); }
}
The above content is small to introduce the hair glass effect of the example code, I hope to help you!