Anj*_*ani 6 android android-glide
我一直在使用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)
如何获得理想的结果?任何帮助将非常感激。
在Glide v4.6.1中,我发现MultiTransformation该类使此操作变得简单:
MultiTransformation<Bitmap> multiTransformation = new MultiTransformation<>(new CustomTransformation(), new CircleCrop());
Glide.with(DemoActivity.this).load(file)
.apply(RequestOptions.bitmapTransform(multiTransformation))
.into(mPreviewImageView);
Run Code Online (Sandbox Code Playgroud)
创建您自己的CustomTransformationwhich extends CenterCrop,然后在进行自定义转换之前覆盖transform()调用时。super
例如:
Glide.with(Context)
.load(url)
.asBitmap()
.transform(new CenterCrop(context) {
@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
// Call super to have your image center cropped
toTransform = super.transform(pool, toTransform, outWidth, outHeight);
// Apply your own custom transformation
return ImageUtils.fastblur(toTransform, BLUR_RADIUS);
}
@Override
public String getId() {
return "com.example.imageid"
}
})
.placeholder(placeholder)
.into(imageView);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3657 次 |
| 最近记录: |