时间:2021-05-20
第一个为大家介绍图片如何转高斯模拟:
1.方法的实现:
public static void updateBgToBlur(Activity a, Bitmap bmpToBlur, View view, int resId) { BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inJustDecodeBounds = true; opt.inSampleSize = 8; opt.inJustDecodeBounds = false; Bitmap bmp = BitmapFactory.decodeResource(a.getResources(), resId, opt); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) { view.setBackground(null); } else { view.setBackgroundDrawable(null); } if (bmpToBlur != null && !bmpToBlur.isRecycled()) { bmpToBlur.recycle(); } bmpToBlur = blurBitmap(a, bmp); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { view.setBackground(new BitmapDrawable(a.getResources(), bmpToBlur)); } else { view.setBackgroundDrawable(new BitmapDrawable(a.getResources(), bmpToBlur)); } } public static Bitmap blurBitmap(Context c, Bitmap bitmap) { //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(), Bitmap.Config.ARGB_4444); //Instantiate a new Renderscript RenderScript rs = RenderScript.create(c.getApplicationContext()); //Create an Intrinsic Blur Script using the Renderscript ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); //Create the Allocations (in/out) with the Renderscript and the in/out bitmaps Allocation allIn = Allocation.createFromBitmap(rs, bitmap); Allocation allOut = Allocation.createFromBitmap(rs, outBitmap); //Set the radius of the blur blurScript.setRadius(25.f); //Perform the Renderscript blurScript.setInput(allIn); blurScript.forEach(allOut); //Copy the final bitmap created by the out Allocation to the outBitmap allOut.copyTo(outBitmap); //recycle the original bitmap bitmap.recycle(); //After finishing everything, we destroy the Renderscript. rs.destroy(); return outBitmap; }2 调用:
Bitmap bitmap=null; if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { ImageUtil.updateBgToBlur(getActivity(), bitmap, slidingUpPanelLayout, R.drawable.bg_tageditor); } else { slidingUpPanelLayout.setBackgroundResource(R.drawable.bg_tageditor); }二、高斯模糊布局:
项目需求: 现有一个紫色背景图片, 相册图片覆盖在背景图片 , 一个Framlayout 覆盖在这个含有相册图片的背景图中 ,实现模糊盖在上面的高斯模拟效果:
1 引用BlurView:
compile 'com.eightbitlab:supportrenderscriptblur:1.0.0' compile 'com.eightbitlab:blurview:1.3.3' defaultConfig { renderscriptTargetApi 25 //must match target sdk and build tools, 23+ renderscriptSupportModeEnabled true }2.调用:
final float radius = 20; final View decorView = getActivity().getWindow().getDecorView(); //Activity's root View. Can also be root View of your layout (preferably) final ViewGroup rootView = (ViewGroup) decorView.findViewById(android.R.id.content); //set background, if your root layout doesn't have one final Drawable windowBackground = decorView.getBackground(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { mBlurView.setupWith(rootView) .windowBackground(windowBackground) .blurAlgorithm(new RenderScriptBlur(getActivity())) .blurRadius(radius); }else { mBlurView.setupWith(rootView) .windowBackground(windowBackground) .blurAlgorithm(new SupportRenderScriptBlur(getActivity())) .blurRadius(radius); }3 xml
<eightbitlab.com.blurview.BlurView android:id="@+id/blurView" android:layout_width="match_parent" android:layout_height="wrap_content" app:blurOverlayColor="@color/colorOverlay"> <!--Any child View here, TabLayout for example--> </eightbitlab.com.blurview.BlurView>以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
高斯模糊 高斯模糊是美国Adobe图像软件公司开发的一个做图软件:AdobePhotoshop(系列)中的一个滤镜,具体的位置在:滤镜—模糊——高斯模糊。
premiere在为视频添加了高斯模糊效果之后,我们知道默认都是整个视频画面会产生高斯模糊的效果,如果现在我只希望在垂直方向上呈现出高斯模糊的效果的话,该如何来
本文实例为大家分享了Unityshader实现高斯模糊效果的具体代码,供大家参考,具体内容如下正常图:高斯模糊效果图:shader代码:Shader"Custo
本文实例讲述了php使用高斯算法实现图片的模糊处理功能。分享给大家供大家参考,具体如下:?12345678910111213141516171819202122
可以用PS软件操作,虚化图片的方法是: 1、打开图片,点击“滤镜”。 2、“模糊”选择“高斯模糊”。 3、设置合适半径像素即可。 AdobePhotos