我在build.gradle中添加了这种依赖关系以模糊我的imageView:
dependencies {
implementation 'com.jackandphantom.android:blurimage:1.2.0'
}
以及我的MainActivity.java中的以下代码:
bgImage = (ImageView) findViewById(R.id.imageView);
Bitmap bitmap = BlurImage.with(getApplicationContext()).load(R.drawable.profilbackground).intensity(25).getImageBlur();
bgImage.setImageBitmap(bitmap);
问题是这种方式只是模糊到25个半径,而我希望它最大为50或100。那么,如何更改图像视图的半径模糊?请给我一种方法。
答案 0 :(得分:4)
根据说明的文档
该库具有多种方法,可用于保持图像模糊。
BlurImage.with(getApplicationContext()).load(R.drawable.myImage).intensity(20).Async(true).into(imageView);
OR
BlurImage.with(getApplicationContext()).load(bitmap_Image).intensity(20).Async(true).into(imageView);
方法(强度):-强度(整数值)
{增加模糊度,并且限制在0到25之间}
最大限制为25,如果要更改该值,则需要自己分叉并自行解决该功能,或者要求库的作者。
我会告诉你解决方法,
答案 1 :(得分:0)
使用Glide轻松实现模糊:
dependencies {
implementation 'com.github.bumptech.glide:glide:3.7.0'
}
在您的活动/片段中
Glide.with(getActivity()).load(loginDetails.getUserdetail().getImage()).asBitmap().into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
profileImageView.setImageBitmap(BlurImageView.blur(resource));
}
});
BlurImageView.java
public class BlurImageView {
private static final float BITMAP_SCALE = 0.4f;
private static final float BLUR_RADIUS = 25f;
public static Bitmap blur(Bitmap bitmap) {
Bitmap u8_4Bitmap;
if (bitmap.getConfig() == Bitmap.Config.ARGB_8888) {
u8_4Bitmap = bitmap;
} else {
u8_4Bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
}
int width = Math.round(u8_4Bitmap.getWidth() * BITMAP_SCALE);
int height = Math.round(u8_4Bitmap.getHeight() * BITMAP_SCALE);
Bitmap inputBitmap = Bitmap.createScaledBitmap(u8_4Bitmap, width, height, false);
Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);
RenderScript rs = RenderScript.create(UpasargaApplication.getAppContext());
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;
}
}
答案 2 :(得分:0)
实现'com.squareup.picasso:picasso:2.5.2'
<ImageView
android:id="@+id/iv_profilepic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"/>
Target target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { imageViewBackground.setImageBitmap(BlurImage.fastblur(bitmap, 1f, BLUR_PRECENTAGE));
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
imageViewBackground.setImageResource(R.mipmap.ic_launcher);
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
};