这篇文章主要介绍“php图片添加高斯模糊的方法是什么”,在日常操作中,相信很多人在php图片添加高斯模糊的方法是什么问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”php图片添加高斯模糊的方法是什么”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
private static Bitmap activityShot(Activity activity) { /*获取windows中最顶层的view*/ View view = activity.getWindow().getDecorView(); //允许当前窗口保存缓存信息 view.setDrawingCacheEnabled(true); view.buildDrawingCache(true); // //获取状态栏高度 // Rect rect = new Rect(); // view.getWindowVisibleDisplayFrame(rect); // int statusBarHeight = rect.top; // // WindowManager windowManager = activity.getWindowManager(); // // //获取屏幕宽和高 // DisplayMetrics outMetrics = new DisplayMetrics(); // windowManager.getDefaultDisplay().getMetrics(outMetrics); // int width = outMetrics.widthPixels; // int height = outMetrics.heightPixels; // // //去掉状态栏 // Bitmap shotBitmap = Bitmap.createBitmap(view.getDrawingCache(), 0, statusBarHeight, width, // height - statusBarHeight); //压缩系数2,4,8 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); // 截屏view.getDrawingCache() canvas.drawBitmap(view.getDrawingCache(), 0, 0, paint); //销毁缓存信息 view.destroyDrawingCache(); view.setDrawingCacheEnabled(false); return scaledBitmap; }
将return的scaleBitmap放入下面的方法:
private static Bitmap rsBlur(Context context, Bitmap source, int radius) { Bitmap inputBmp = source; //(1) //初始化一个RenderScript Context RenderScript renderScript = RenderScript.create(context); // Allocate memory for Renderscript to work with //(2) //创建输入输出的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. //创建ScriptIntrinsic ScriptIntrinsicBlur scriptIntrinsicBlur = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript)); //(4) //填充数据 scriptIntrinsicBlur.setInput(input); //(5) // Set the blur radius //设置模糊半径 scriptIntrinsicBlur.setRadius(radius); //(6) // Start the ScriptIntrinisicBlur //启动内核 scriptIntrinsicBlur.forEach(output); //(7) // Copy the output to the blurred bitmap //copy数据 output.copyTo(inputBmp); //(8) //销毁renderScript renderScript.destroy(); return inputBmp; }
不用的时候要remove掉:
public void removeMask(){ if (group != null){ for(int i=0;i<group.getChildCount();i++){ group.removeView(imageView); } } }
到此,关于“php图片添加高斯模糊的方法是什么”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。