一、通过 ImageView 设置 以及加了高斯模糊的 Bitmap 对象
ImageLoaderUtils.loadImgWithListener(this, "https://.../uploads/20210813143221243.png" + "?x-oss-process=image/resize,w_" + CommonUtil.dip2px(100), new CustomTarget<Drawable>() {
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition transition) {
Bitmap bitmap = null;
if (resource instanceof BitmapDrawable) {
bitmap = ((BitmapDrawable) resource).getBitmap();
}
//卡牌底部出现(加模糊),持续170ms
showCardBlur(bitmap);
showPlayRewardView(new RewardModel.RewardData(), cards_big_view, 0); //todo 测试数据,上线前需删除
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
private synchronized void showCardBlur(Bitmap bitmap) {
new Thread() {
@Override
public void run() {
recycleBlurBitmap();
//获取卡片整体区域的view的Bitmap
try {
if(bitmap != null){
if(handler == null){
handler = new MyHandler();
}
blurBitmap = BitmapUtils.rsBlur(VideoPlayActivity.this, bitmap, 25);
Message message = handler.obtainMessage();
message.what = 100; //通知显示高斯模糊
handler.sendMessage(message);
}
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
}.start();
}
if(msg.what == MSG_BLUR_BITMAP){
//todo 高斯模糊
cards_big_view.iv_big_icon.setImageBitmap(blurBitmap);
handler.postDelayed(new Runnable() {
@Override
public void run() {
ImageLoaderUtils.loadRoundCornerImg(VideoPlayActivity.this,"https://.../uploads/20210813143221243.png" + "?x-oss-process=image/resize,w_" + CommonUtil.dip2px(100),cards_big_view.iv_big_icon
, CommonUtil.dip2px(15),true,true,false,false);
}
}, 170);
}
二、通过 Glide 设置 高斯模糊的 BitmapTransformation 转化器
RoundedCornersTransform roundedCornersTransform = new RoundedCornersTransform(this, CommonUtil.dip2px(15));
roundedCornersTransform.setNeedCorner(true, true, true, true);
MultiTransformation<Bitmap> multiTransformation = new MultiTransformation<>(new BlurTransformation(CommonUtil.dip2px(15), 3), roundedCornersTransform);
Glide.with(this).load("https://.../uploads/20210813143221243.png" + "?x-oss-process=image/resize,w_" + CommonUtil.dip2px(100))
.apply(RequestOptions.bitmapTransform(multiTransformation))
.into(cards_big_view.iv_big_icon);
两种方式都要做这个设置
defaultConfig {
applicationId ""
minSdkVersion rootProject.ext.android.minSdkVersion
targetSdkVersion rootProject.ext.android.targetSdkVersion
versionCode rootProject.ext.android.versionCode
versionName rootProject.ext.android.versionName
multiDexEnabled true
renderscriptTargetApi 19 //使用renderscript的设置
renderscriptSupportModeEnabled true //使用renderscript的设置
}