如下图所示,模糊背景图像的最佳方法是什么?我看到了一些代码和库,但它们已经有几年的历史了,或者像BlurBehind库一样,但它不会产生同样的效果。提前感谢!
发布于 2015-07-27 05:27:08
要做到这一点,最简单的方法是使用库。看一下这个:https://github.com/wasabeef/Blurry
使用该库,您只需执行以下操作:
Blurry.with(context)
.radius(10)
.sampling(8)
.color(Color.argb(66, 255, 255, 0))
.async()
.onto(rootView);
发布于 2017-12-26 13:19:58
您可以使用:
Glide.with(getContext()).load(R.mipmap.bg)
.apply(bitmapTransform(new BlurTransformation(22)))
.into((ImageView) view.findViewById(R.id.imBg));
这需要在build.gradle
文件中添加以下内容:
implementation 'jp.wasabeef:glide-transformations:4.0.0'
发布于 2017-11-13 18:43:03
实现这一目标的最简单方法如下所示:
i)
Glide.with(context.getApplicationContext())
.load(Your Path)
.override(15, 15) // (change according to your wish)
.error(R.drawable.placeholder)
.into(image.score);
否则,您可以遵循下面的代码。
II)
1.创建一个类。(代码如下)
public class BlurTransformation extends BitmapTransformation {
private RenderScript rs;
public BlurTransformation(Context context) {
super( context );
rs = RenderScript.create( context );
}
@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
Bitmap blurredBitmap = toTransform.copy( Bitmap.Config.ARGB_8888, true );
// Allocate memory for Renderscript to work with
Allocation input = Allocation.createFromBitmap(
rs,
blurredBitmap,
Allocation.MipmapControl.MIPMAP_FULL,
Allocation.USAGE_SHARED
);
Allocation output = Allocation.createTyped(rs, input.getType());
// Load up an instance of the specific script that we want to use.
ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setInput(input);
// Set the blur radius
script.setRadius(10);
// Start the ScriptIntrinisicBlur
script.forEach(output);
// Copy the output to the blurred bitmap
output.copyTo(blurredBitmap);
toTransform.recycle();
return blurredBitmap;
}
@Override
public String getId() {
return "blur";
}
}
2.使用Glide将图像设置为ImageView。
例如:
Glide.with(this)
.load(expertViewDetailsModel.expert.image)
.asBitmap()
.transform(new BlurTransformation(this))
.into(ivBackground);
https://stackoverflow.com/questions/31641973
复制相似问题