首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用glide库旋转图像?(就像毕加索的作品)

如何使用glide库旋转图像?(就像毕加索的作品)
EN

Stack Overflow用户
提问于 2016-01-15 20:46:20
回答 2查看 13.9K关注 0票数 10

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

//使用的代码

代码语言:javascript
复制
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

代码语言:javascript
复制
Glide.with(context)
                .load(link)
                .asBitmap()
                .transform(new MyTransformation(context, 90))
                .into(imageView);

提前谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-01-27 20:51:33

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

代码语言:javascript
复制
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;
}

以及如何使用它:

代码语言:javascript
复制
   Glide.with(mContext)
            .load(//your url)
            .asBitmap()
            .centerCrop()
            .transform(new MyTransformation(mContext, 90))
            .diskCacheStrategy(DiskCacheStrategy.RESULT)
            .into(//your view);

有关更多情况或exif int值,请检查android.media.ExifInterface中的公共常量

票数 24
EN

Stack Overflow用户

发布于 2018-05-09 00:02:04

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

代码语言:javascript
复制
Glide.with(mCtx)
            .load(uploadImage.getImageUrl())
            .into(holder.imageView);
    holder.imageView.setRotation(uploadImage.getmRotation());

我希望你能理解。只需获取放入.into(x)方法中的文件,然后编写x.setRotaion()

票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34811415

复制
相关文章

相似问题

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