Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
像iOS一样使用彩色阴影(如深灰色)获得模糊图像的效果,但在Android中_Android - Fatal编程技术网

像iOS一样使用彩色阴影(如深灰色)获得模糊图像的效果,但在Android中

像iOS一样使用彩色阴影(如深灰色)获得模糊图像的效果,但在Android中,android,Android,我怎样才能创造出你在iOS中看到的效果;当一个对话框打开时,背景屏幕也会变得模糊,就像Android中的彩色阴影一样 我必须要得到这样的效果,但我不能得到这样的效果 对于模糊效果,我拍摄了当前视图的屏幕截图并模糊了该图像,但我需要一个类似下面演示图像中的颜色效果 我想要的效果如图所示。我怎样才能得到这种效果 演示图像(带颜色阴影的模糊)使用以下类别 public class BlurBuilder { private static final float BITMAP_SCALE = 0

我怎样才能创造出你在iOS中看到的效果;当一个对话框打开时,背景屏幕也会变得模糊,就像Android中的彩色阴影一样

我必须要得到这样的效果,但我不能得到这样的效果

对于模糊效果,我拍摄了当前视图的屏幕截图并模糊了该图像,但我需要一个类似下面演示图像中的颜色效果

我想要的效果如图所示。我怎样才能得到这种效果


演示图像(带颜色阴影的模糊)

使用以下类别

public class BlurBuilder {
    private static final float BITMAP_SCALE = 0.05f;
    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;
    }
}
在需要的地方也可以使用它,如下所示:

Bitmap blurredBitmap = BlurBuilder.blur(mContext, icn);
rootlay.setBackgroundDrawable(new BitmapDrawable(getResources(), blurredBitmap));
使用颜色过滤器。 以下代码取自


使用任何方法模糊图像。您可以找到各种类型的库来执行此操作

我用过

当图像变得模糊时,你只需添加一行即可

BlurImageView.setColorFilter(Color.argb(155, 0, 0, 0), PorterDuff.Mode.SRC_ATOP);
这将为图像视图提供阴影
根据需要更改Color.argb的参数

有许多库可用于模糊效果,我可以获得模糊效果,但我还需要颜色阴影效果(如图像中的深灰色)有了模糊效果,@DimaKozhevin的可能复制品,我已经浏览了你们的链接,但这只会帮助我模糊图像,而不会像图片中的深灰色那样得到颜色阴影。我的问题是如何一次获得这两种颜色?这使图像只模糊,而不像图像中的颜色阴影(深灰色阴影),但它为您正在使用的位图元素着色,而不是模糊的颜色。
BlurImageView.setColorFilter(Color.argb(155, 0, 0, 0), PorterDuff.Mode.SRC_ATOP);