首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未调用Glide BitmapTransformation

未调用Glide BitmapTransformation
EN

Stack Overflow用户
提问于 2018-01-22 18:12:20
回答 1查看 657关注 0票数 0

我正试着在Glide中旋转我的图像。正如文档中所说的,我已经创建了BitmapTransformation。问题是重写的方法transform不会被调用,所以图像根本不会旋转。我使用的是Glide 3.7.0

代码语言:javascript
复制
    @Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    Uri imageUri = this.imageUri;

    Glide.with(getContext())
            .load(imageUri)
            .transform(new RotateTransformation(getContext(), 90))
            .fitCenter()
            .into(imageView);
}

public class RotateTransformation extends BitmapTransformation {

    private float rotateRotationAngle = 0f;

    public RotateTransformation(Context context, float rotateRotationAngle) {
        super(context);

        this.rotateRotationAngle = rotateRotationAngle;
    }

    @Override
    protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
        Matrix matrix = new Matrix();

        matrix.postRotate(rotateRotationAngle);

        return Bitmap.createBitmap(toTransform, 0, 0, toTransform.getWidth(), toTransform.getHeight(), matrix, true);
    }

    @Override
    public String getId() {
        return "rotate" + rotateRotationAngle;
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-22 18:25:41

更新

代码语言:javascript
复制
Glide.with(getContext())
            .load(imageUri)
            .transform(new RotateTransformation(getContext(), 90))
            .fitCenter()
            .into(imageView);

代码语言:javascript
复制
Glide.with(getContext())
            .load(imageUri)
            .fitCenter()
            .transform(new RotateTransformation(getContext(), 90))
            .into(imageView);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48379104

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档