模糊线性布局背景

时间:2016-08-10 13:47:41

标签: android android-layout

在我的应用中,我有一个LinearLayout,它是透明的,并附加到WindowManager。我希望LinearLayout Blur使LinearLayout后面的所有内容ImageView 1}}看起来很模糊。我已经经历了各种各样的来源,因为我得到了如何使RenderScript Api模糊,我已经成功地使用 private static final float BLUR_RADIUS = 25f; Bitmap outputBitmap = Bitmap.createBitmap(image); final RenderScript renderScript = RenderScript.create(this); Allocation tmpIn = Allocation.createFromBitmap(renderScript, image); Allocation tmpOut = Allocation.createFromBitmap(renderScript, outputBitmap); //Intrinsic Gausian blur filter ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript)); theIntrinsic.setRadius(BLUR_RADIUS); theIntrinsic.setInput(tmpIn); theIntrinsic.forEach(tmpOut); tmpOut.copyTo(outputBitmap); return outputBitmap; } and finally adding it with `ImageView` ImageView imageView=(ImageView)findViewById(image-id); Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.nature); Bitmap blurredBitmap = blur(bitmap); imageView.setImageBitmap(blurredBitmap); 这里是代码:

ImageView

但遗憾的是它只会模糊ImageView。任何模糊布局或修改上述代码以使用布局的解决方案。

大家好我必须知道如何成功模糊let arr1: boolean[] = []; let arr2: boolean[] = new Array(); let arr3: boolean[] = Array(); let arr4: Array<boolean> = []; let arr5: Array<boolean> = new Array(); let arr6: Array<boolean> = Array(); let arr7 = [] as boolean[]; let arr8 = new Array() as Array<boolean>; let arr9 = Array() as boolean[]; let arr10 = <boolean[]> []; let arr11 = <Array<boolean>> new Array(); let arr12 = <boolean[]> Array(); ,但我怎么能模糊透明的LinearLayout.Is有任何解决方案请帮助我

1 个答案:

答案 0 :(得分:1)

我创建了一个example project来举例说明可能使用的过程(main code)。

此示例的目的是展示如何使用RenderScript模糊通用视图。 该示例的作用(当点击按钮“Blur it!”时):

1)模糊所选视图

对于此示例,所选视图必须包含在更大的容器中(例如,LinearLayout)。

模糊过程:

  • 获取原始视图的屏幕截图。

    Bitmap getViewScreenshot(View v) {
        v.setDrawingCacheEnabled(true);
        Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
        v.setDrawingCacheEnabled(false);
    
        return b;
    }
    
  • 实例化所有RenderScript分配(一个用于输入,一个用于模糊输出)。

    allocOriginalScreenshot = Allocation.createFromBitmap(mRS, viewScreenshot);
    // Creates an allocation where to store the blur results
    allocBlurred = Allocation.createTyped(mRS, allocOriginalScreenshot.getType(), Allocation.USAGE_SCRIPT | Allocation.USAGE_IO_OUTPUT);
    
  • 创建TextureView以显示模糊结果。
  • 用原始视图替换新的TextureView。在此过程中,新视图将保存在原始视图的“tag”字段中,以便稍后可以使用新的TextureView替换原始视图。

    void replaceView(View originalView, View newView) {
        originalView.setTag(newView);
    
        newView.setLayoutParams(new FrameLayout.LayoutParams(originalView.getLayoutParams()));
    
        ViewGroup parent = (ViewGroup) originalView.getParent();
        int index = parent.indexOfChild(originalView);
        parent.removeView(originalView);
    
        parent.addView(newView, index);
    }   
    
  • 使用ScriptIntrinsicBlur类模糊屏幕截图。

    void executeBlur() {
        Log.d(TAG, "Executing blur");
    
        scriptIntrinsicBlur.setInput(allocOriginalScreenshot);
        scriptIntrinsicBlur.forEach(allocBlurred);
    
        allocBlurred.ioSend();
    }
    

2)显示一个简单的对话框

3)取消原始视图

unblur进程从布局中删除TextureView并恢复原始视图。

参考:RenderScript: parallel computing on Android, the easy wayDali library