1. Software Blur
Method of using the software. With CPU calculation, there is no SDK version number required.
:
Key Blur code GitHub link
Original link
Translation links
Demo Sample Code
This address: http://blog.csdn.net/csqingchen/article/details/43817975
2. Using Renderscript blur,
Scriptintrinsicblur requires Android SDK version number minimum 17.
Google's official documentation links
Use the code specifically for the following:
/** * By calling the system Gaussian Blur API method Fuzzy * * @param bitmap source bitmap * @param outbitmap out B Itmap * @param radius 0 < Radius <= * @param Context context * @return out bitmap * / Public StaticBitmapBlurbitmap(Bitmap Bitmap, Bitmap Outbitmap,floatRADIUS, Context context) {//let ' s create an empty bitmap with the same size of the bitmap we want to blur //bitmap outbitmap = Bitmap.createbitmap (Bitmap.getwidth (), Bitmap.getheight (), config.argb_8888); //instantiate a new renderscriptRenderscript rs = renderscript.create (context);//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 BlurBlurscript.setradius (RADIUS);//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 bitmap//Bitmap.recycle (); //after Finishing everything, we destroy the Renderscript.Rs.destroy ();returnOutbitmap; }
3. Bitmap Zoom Processing
These two kinds of fuzzy methods, the smaller the bitmap size, the faster processing. In particular method one. In order to achieve the desired blur effect, we usually need to deal with the source bitmap scaling. The scaling code is as follows:
/** * Proportional compression picture * * @param sourcebitmap Source bitmap * @param scalefactor greater than 1. Reduce bitmap * @return reduce scalefactor times after bitmap */ Public StaticBitmapCompressbitmap(Bitmap Sourcebitmap,floatScalefactor) {Bitmap overlay = Bitmap.createbitmap ((int) (Sourcebitmap.getwidth ()/Scalefactor), (int) (Sourcebitmap.getheight ()/scalefactor), config.argb_8888); Canvas Canvas =NewCanvas (overlay); Canvas.translate (0,0); Canvas.scale (1/Scalefactor,1/scalefactor); Paint paint =NewPaint (Paint.anti_alias_flag | Paint.filter_bitmap_flag); Canvas.drawbitmap (Sourcebitmap,0,0, paint);returnOverlay }
4. Change the contrast/brightness of the picture
See Code gaze and Demo sample code for details
/** * Change the contrast of the picture to achieve the effect of making the picture light and dark * * @param srcbitmap Source bitmap * @param contrast picture on Degree. 0: All Black. Less than 1, darker than the original, 1.0f original, greater than 1 brighter than the original * @return bitmap * / Public StaticBitmapDarkbitmap(Bitmap Srcbitmap,floatContrast) {floatOffset = (float)0.0;//picture RGB Offset intImgHeight, ImgWidth; ImgHeight = Srcbitmap.getheight (); ImgWidth = Srcbitmap.getwidth (); Bitmap bmp = Bitmap.createbitmap (ImgWidth, ImgHeight, config.argb_8888); ColorMatrix Cmatrix =NewColorMatrix (); Cmatrix.set (New float[]{contrast,0,0,0, offset,0, contrast,0,0, offset,0,0, contrast,0, offset,0,0,0,1,0}); Paint paint =NewPaint (); Paint.setcolorfilter (NewColormatrixcolorfilter (Cmatrix)); Canvas Canvas =NewCanvas (BMP); Canvas.drawbitmap (Srcbitmap,0,0, paint);returnBmp }
Android Blur effect Summary