所以,有人知道如何使用Glide显示带圆角的图像吗?我正在使用Glide加载图像,但我不知道如何将舍入的参数传递给此库.
我需要显示图像如下例子:

我需要从图像底部切掉 20px 并缓存它,这样设备就不必每次用户再次看到图像时都一遍又一遍地裁剪它,否则会对电池等造成不良影响,对吗?
这是我到目前为止所拥有的:
Glide
.with(context)
.load(imgUrl)
.into(holder.image)
fun cropOffLogo(originalBitmap: Bitmap) : Bitmap {
return Bitmap.createBitmap(
originalBitmap,
0,
0,
originalBitmap.width,
originalBitmap.height - 20
)
}
Run Code Online (Sandbox Code Playgroud)
我该如何使用cropOffLogowith glide?
编辑:
我尝试使用https://github.com/bumptech/glide/wiki/Transformations#custom-transformations
private static class CutOffLogo extends BitmapTransformation {
public CutOffLogo(Context context) {
super(context);
}
@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform,
int outWidth, int outHeight) {
Bitmap myTransformedBitmap = Bitmap.createBitmap(
toTransform,
10,
10,
toTransform.getWidth(),
toTransform.getHeight() - 20);
return myTransformedBitmap;
}
}
Run Code Online (Sandbox Code Playgroud)
并得到这些错误:
Modifier 'private' not allowed here
Modifier …Run Code Online (Sandbox Code Playgroud) 我一直在使用Glide在我的应用程序中加载图像。我有一个自定义转换,正在将图像加载到中时使用ImageView。
问题是我想对centerCrop提取的图像应用我的自定义转换和两者。但滑翔仅使用我的自定义转换和显示图像ImageView用fitXY。
这是我的代码:
Glide.with(context)
.load(uri)
.placeholder(R.drawable.image_id)
.transform(new CustomTransformation(context))
.centerCrop()
.into(imageView);
Run Code Online (Sandbox Code Playgroud)
如何获得理想的结果?任何帮助将非常感激。