Viťa Morávek
Viťa Morávek

Reputation: 122

Glide BitmapTransformation is not called

I'm trying to rotate my image in Glide. I've created BitmapTransformation as it's said in the documentation. Problem is that overrided method transform is not called so image is not rotated at all. I'm using Glide 3.7.0

    @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;
    }
}

Upvotes: 0

Views: 940

Answers (1)

Akash Sharma
Akash Sharma

Reputation: 286

update

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

to

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

Upvotes: 1

Related Questions