不调用 Glide BitmapTransformation
Glide BitmapTransformation is not called
我正在尝试在 Glide 中旋转图像。
我已经按照文档中的说明创建了 BitmapTransformation。
问题是重写的方法 transform 没有被调用,所以图像根本没有旋转。我正在使用 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;
}
}
更新
Glide.with(getContext())
.load(imageUri)
.transform(new RotateTransformation(getContext(), 90))
.fitCenter()
.into(imageView);
至
Glide.with(getContext())
.load(imageUri)
.fitCenter()
.transform(new RotateTransformation(getContext(), 90))
.into(imageView);
我正在尝试在 Glide 中旋转图像。 我已经按照文档中的说明创建了 BitmapTransformation。 问题是重写的方法 transform 没有被调用,所以图像根本没有旋转。我正在使用 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;
}
}
更新
Glide.with(getContext())
.load(imageUri)
.transform(new RotateTransformation(getContext(), 90))
.fitCenter()
.into(imageView);
至
Glide.with(getContext())
.load(imageUri)
.fitCenter()
.transform(new RotateTransformation(getContext(), 90))
.into(imageView);