android – 如何使活动背景透明并模糊背景

当我启动我的应用程序时,它会启动一个应该具有透明标题的Activity,并且当前显示的任何内容都应该模糊.

我能够获得透明度.但我无法弄清楚如何模糊背景.例如,如果我从主屏幕启动应用程序,那么主屏幕应该是可见的但模糊了.

我有一个想法是使用Framebuffer来获取当前显示的数据,但是如何将其转换为位图,我可以使用它来绘制图像而不保存图像并直接使用数据.

我也知道我们可以通过按电源和音量按钮来截取屏幕截图.有没有人知道android中的代码在哪里?我的应用程序将具有系统访问权

解决方法

how to blur the background?

您可以使用支持库中提供的RenderScript

public class BlurBuilder {
    private static final float BITMAP_SCALE = 0.4f;
    private static final float BLUR_RADIUS = 7.5f;

    public static Bitmap blur(Context context,Bitmap image) {
        int width = Math.round(image.getWidth() * BITMAP_SCALE);
        int height = Math.round(image.getHeight() * BITMAP_SCALE);

        Bitmap inputBitmap = Bitmap.createScaledBitmap(image,width,height,false);
        Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);

        RenderScript rs = RenderScript.create(context);
        ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs,Element.U8_4(rs));
        Allocation tmpIn = Allocation.createFromBitmap(rs,inputBitmap);
        Allocation tmpOut = Allocation.createFromBitmap(rs,outputBitmap);
        theIntrinsic.setRadius(BLUR_RADIUS);
        theIntrinsic.setInput(tmpIn);
        theIntrinsic.forEach(tmpOut);
        tmpOut.copyTo(outputBitmap);

        return outputBitmap;
    }
}

有关详细信息,请参阅this link

或者你可以使用Blurry

Does anyone has an idea where is the code in android to do that?

要获取应用程序屏幕的屏幕截图,请参阅this link

相关文章

Android 如何解决dialog弹出时无法捕捉Activity的back事件 在...
Android实现自定义带文字和图片的Button 在Android开发中经常...
Android 关于长按back键退出应用程序的实现最近在做一个Andr...
android自带的时间选择器只能精确到分,但是对于某些应用要求...