如何使用滑行库旋转图像? (就像毕加索)

How to rotate image using glide library? (Like in picasso)

我正在尝试使用 glide 库旋转图像。以前,可以和毕加索一起做(由于一个问题,我搬到了滑翔)。现在我在滑行中缺少旋转功能。我尝试使用转换但没有用。

// 使用的代码

public class MyTransformation extends BitmapTransformation {

private float rotate = 0f;

public MyTransformation(Context context, float rotate) {
    super(context);
    this.rotate = rotate;
}

@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform,
                           int outWidth, int outHeight) {
    return rotateBitmap(toTransform, rotate);
}

@Override
public String getId() {
    return "com.example.helpers.MyTransformation";
}

public static Bitmap rotateBitmap(Bitmap source, float angle)
{
    Matrix matrix = new Matrix();
    matrix.postRotate(angle);
    return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
}
}

// 滑行

Glide.with(context)
                .load(link)
                .asBitmap()
                .transform(new MyTransformation(context, 90))
                .into(imageView);

提前致谢。

也许您已经自己找到了解决方案,如果没有,也许这对您有所帮助。我使用此代码段来旋转从相机获得的图像。

public MyTransformation(Context context, int orientation) {
    super(context);
    mOrientation = orientation;
}

@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
    int exifOrientationDegrees = getExifOrientationDegrees(mOrientation);
    return TransformationUtils.rotateImageExif(toTransform, pool, exifOrientationDegrees);
}

private int getExifOrientationDegrees(int orientation) {
    int exifInt;
    switch (orientation) {
        case 90:
            exifInt = ExifInterface.ORIENTATION_ROTATE_90;
            break;
        // other cases
        default:
            exifInt = ExifInterface.ORIENTATION_NORMAL;
            break;
    }
    return exifInt;
}

以及如何使用它:

   Glide.with(mContext)
            .load(//your url)
            .asBitmap()
            .centerCrop()
            .transform(new MyTransformation(mContext, 90))
            .diskCacheStrategy(DiskCacheStrategy.RESULT)
            .into(//your view);

对于更多情况或 exif int 值,请检查 android.media.ExifInterface

中的 public 常量

我发现的一种方法是这样。

Glide.with(mCtx)
            .load(uploadImage.getImageUrl())
            .into(holder.imageView);
    holder.imageView.setRotation(uploadImage.getmRotation());

希望你明白。 只需获取您放入 .into(x) 方法中的文件 然后写 x.setRotaion()