繁体   English   中英

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

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

我正在尝试使用滑动库旋转图像。 以前,能够与毕加索合作(由于一个问题,我开始滑行)。 现在我在滑行中缺少旋转功能。 我尝试使用转换,但没有工作。

//使用的代码

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);

对于更多case或exif int值,检查android.media.ExifInterface中的公共常量

我找到的一种方法就是这样。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM