我正在尝试使用Glide显示模糊图像,但显示错误图像。我不知道为什么会显示错误图像。URL工作正常,但仍然只显示错误图像
这是我的代码
Glide.with(context)
.load("http://www.gadgetsaint.com/wp-content/uploads/2016/11/cropped-web_hi_res_512.png")
.diskCacheStrategy(DiskCacheStrategy.NONE)
.bitmapTransform(new BlurTransformation(context))
.error(R.drawable.error_image)
.into(imageView);
Run Code Online (Sandbox Code Playgroud)
模糊转换类:
public class BlurTransformation extends BitmapTransformation {
private RenderScript rs;
public BlurTransformation(Context context) {
super(context);
rs = RenderScript.create(context);
}
@SuppressLint("NewApi")
@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(100);
// 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";
}
}
Run Code Online (Sandbox Code Playgroud)
Dee*_*put 16
implementation 'jp.wasabeef:glide-transformations:4.0.0
对于最新版本,请始终从此处检查更改日志Glide 转换 Glide.with(this)
.load(R.drawable.demo)
.apply(bitmapTransform(BlurTransformation(25, 3)))
.into(imageView)
Run Code Online (Sandbox Code Playgroud)
对于滑翔V3,
Glide.with(context).load(imagePath).transform(new BlurTransformation(context))
.into(imageView);
Run Code Online (Sandbox Code Playgroud)
我正在使用这个类进行模糊变换
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";
}
Run Code Online (Sandbox Code Playgroud)
}
| 归档时间: |
|
| 查看次数: |
13811 次 |
| 最近记录: |