我需要从图片底部裁剪20像素并缓存它,这样设备在用户再次查看图片时就不需要一遍又一遍地裁剪,否则会对电池等产生不良影响,对吧?
目前,我已经做到了这一点:
目前,我已经做到了这一点:
Glide
.with(context)
.load(imgUrl)
.into(holder.image)
fun cropOffLogo(originalBitmap: Bitmap) : Bitmap {
return Bitmap.createBitmap(
originalBitmap,
0,
0,
originalBitmap.width,
originalBitmap.height - 20
)
}
我如何在glide
中使用cropOffLogo
?
编辑:
我尝试使用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;
}
}
并且出现这些错误:
Modifier 'private' not allowed here
Modifier 'static' not allowed here
'BitmapTransformation()' in 'com.bumptech.glide.load.resource.bitmap.BitmapTransformation' cannot be applied to '(android.content.Context)'