如何创建像你在iOS中看到的效果;当对话框打开时,背景屏幕也会变得模糊,就像安卓中的色调一样。
我已经关注了this link来获得这个效果,但是我不能像这样得到合适的效果。
对于模糊效果,我使用当前视图的屏幕截图并模糊该图像,但我需要一个颜色效果,如下面的演示图像所示。
我想要的效果如图所示。怎样才能达到这个效果呢?
演示图像(带有彩色阴影的模糊)

发布于 2019-03-15 17:16:23
使用ColorFilter。以下代码取自Blurry
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
//...omitted...
Paint paint = new Paint();
paint.setFlags(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG);
//replace factor.color with your desired color, e.g Color.argb(200,200,200,200)
PorterDuffColorFilter filter =
new PorterDuffColorFilter(factor.color, PorterDuff.Mode.SRC_ATOP);
paint.setColorFilter(filter);
canvas.drawBitmap(source, 0, 0, paint);
//blur
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
try {
bitmap = Blur.rs(context, bitmap, factor.radius);
} catch (RSRuntimeException e) {
bitmap = Blur.stack(bitmap, factor.radius, true);
}
} else {
bitmap = Blur.stack(bitmap, factor.radius, true);
}
//...omitted...发布于 2020-02-26 18:08:54
使用任何方法来模糊您的图像。您可以找到各种类型库来做到这一点。
我用过Blur Image View。
当图像变模糊时,您只需添加一行即可。
BlurImageView.setColorFilter(Color.argb(155, 0, 0, 0), PorterDuff.Mode.SRC_ATOP);这将为您的图像视图添加阴影根据需要更改Color.argb的参数
发布于 2017-10-13 15:08:46
在类下面使用它
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));https://stackoverflow.com/questions/46724209
复制相似问题