The method of realizing fuzzy processing of layout background in Android _android

Source: Internet
Author: User

When mimicking the IOS password input page, it was found to have a fuzzy background, so I learned it and recorded it for use. In Android, the following methods are implemented
The http://www.jb51.net/article/64781.htm of the Bible

private void Applyblur () {  
    
  //Get wallpaper manager  
  Wallpapermanager Wallpapermanager = wallpapermanager.getinstance ( This.getcontext ());  
  Get the current wallpaper  
  drawable wallpaperdrawable = wallpapermanager.getdrawable ();  
  Convert drawable to Bitmap  
  Bitmap bmp = ((bitmapdrawable) wallpaperdrawable). Getbitmap ();  
   
  Blur (BMP);  
  

The reason for the following is to do small and big processing, because only rely on Scriptintrinsicblur to deal with the mode, can not reach the effect of the model, if you need to deepen the pattern effect of the need to reduce the background picture, after processing and then enlarged. This can be done using the matrix. , and it can shorten the blur time.

@TargetApi (build.version_codes.  
  JELLY_BEAN_MR1) private void Blur (Bitmap bkg) {Long Startms = System.currenttimemillis ();  
 
  float radius = 20; 
  bkg = Small (bkg); 
 
  Bitmap Bitmap = bkg.copy (Bkg.getconfig (), true); 
  Final Renderscript rs = renderscript.create (This.getcontext ()); Final allocation input = Allocation.createfrombitmap (RS, bkg, Allocation.MipmapControl.MIPMAP_NONE, Allocation.usag 
  E_script); 
  Final allocation output = allocation.createtyped (RS, Input.gettype ()); 
  Final Scriptintrinsicblur script = Scriptintrinsicblur.create (RS, Element.u8_4 (RS)); 
  Script.setradius (RADIUS); 
  Script.setinput (input); 
  Script.foreach (output); 
 
  Output.copyto (bitmap); 
  Bitmap = big (bitmap);  
  SetBackground (New Bitmapdrawable (Getresources (), bitmap));  
  Rs.destroy ();  
LOG.D ("Zhangle", "Blur take Away:" + (System.currenttimemillis ()-STARTMS) + "MS");  
   private static Bitmap big (Bitmap Bitmap) {Matrix matrix = new Matrix (); Matrix.postScale (4f,4f); 
   Long and wide magnification reduces the proportion of Bitmap resizebmp = Bitmap.createbitmap (Bitmap,0,0,bitmap.getwidth (), Bitmap.getheight (), matrix,true); 
 return resizebmp;  
   private static Bitmap Small (Bitmap Bitmap) {Matrix matrix = new Matrix (); Matrix.postscale (0.25f,0.25f); 
   Long and wide magnification reduces the proportion of Bitmap resizebmp = Bitmap.createbitmap (Bitmap,0,0,bitmap.getwidth (), Bitmap.getheight (), matrix,true); 
return resizebmp; 
 }

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.