Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the method of adding Gaussian blur to php images?

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "what is the method of adding Gaussian blur to php pictures". In daily operation, I believe that many people have doubts about the method of adding Gaussian blur to php pictures. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "what is the method of adding Gaussian blur to php pictures?" Next, please follow the editor to study!

Private static Bitmap activityShot (Activity activity) {/ * get the topmost view*/ View view = activity.getWindow () .getDecorView () in windows; / / allow the current window to save cache information view.setDrawingCacheEnabled (true); view.buildDrawingCache (true); / get the height of the status bar / / Rect rect = new Rect (); / / view.getWindowVisibleDisplayFrame (rect) / / int statusBarHeight = rect.top;//// WindowManager windowManager = activity.getWindowManager (); / get screen width and height / / DisplayMetrics outMetrics = new DisplayMetrics (); / / windowManager.getDefaultDisplay () .getMetrics (outMetrics); / / int width = outMetrics.widthPixels;// int height = outMetrics.heightPixels / / remove the status bar / / Bitmap shotBitmap = Bitmap.createBitmap (view.getDrawingCache (), 0, statusBarHeight, width,// height-statusBarHeight); / / Compression factor 2min4 float scaleFactor = 8 Bitmap scaledBitmap = Bitmap.createBitmap ((int) (view.getMeasuredWidth () / scaleFactor), (int) (view.getMeasuredHeight () / scaleFactor), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas (scaledBitmap); canvas.translate (- view.getLeft () / scaleFactor,-view.getTop () / scaleFactor) Canvas.scale (1 / scaleFactor, 1 / scaleFactor); Paint paint = new Paint (); paint.setFlags (Paint.FILTER_BITMAP_FLAG); / / screenshot view.getDrawingCache () canvas.drawBitmap (view.getDrawingCache (), 0,0, paint); / / destroy cache information view.destroyDrawingCache (); view.setDrawingCacheEnabled (false); return scaledBitmap;}

Put the scaleBitmap of return into the following method:

Private static Bitmap rsBlur (Context context, Bitmap source, int radius) {Bitmap inputBmp = source; / / (1) / / initialize a RenderScript Context RenderScript renderScript = RenderScript.create (context); / / Allocate memory for Renderscript to work with / (2) / / create input and output allocation final Allocation input = Allocation.createFromBitmap (renderScript, inputBmp) Final Allocation output = Allocation.createTyped (renderScript, input.getType ()) / / (3) / / Load up an instance of the specific script that we want to use. / / create ScriptIntrinsic ScriptIntrinsicBlur scriptIntrinsicBlur = ScriptIntrinsicBlur.create (renderScript, Element.U8_4 (renderScript)); / / (4) / / fill data scriptIntrinsicBlur.setInput (input); / / (5) / / Set the blur radius / / set blur radius scriptIntrinsicBlur.setRadius (radius) / / (6) / / Start the ScriptIntrinisicBlur / / Boot kernel scriptIntrinsicBlur.forEach (output); / / (7) / / Copy the output to the blurred bitmap / / copy data output.copyTo (inputBmp); / / (8) / / destroy renderScript renderScript.destroy (); return inputBmp;}

Drop remove when you are not in use:

Public void removeMask () {if (group! = null) {for (int iTuno)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report