Android 效率开发之图片---Glide 旋转图片处理

    事实上Glide会对旋转的图片正确处理,比如你在三星手机上拍照旋转了90度,用Glide 加载的话,会正确显示。

   通过Glide 强大的图片变换功能,我们也可以旋转图片,关于Glide 的图片变换请参考:Android图片加载框架最全解析(五),Glide强大的图片变换功能,关于图片旋转请参考 :Android 效率开发之图片旋转处理,图片旋转的本质是相同的,如下:


自定义图片变换类继承BitmapTransformation :

/**
 * 旋转变换
 */

public class RotateTransformation  extends BitmapTransformation{

    //旋转默认0
    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);
        //生成新的Bitmap
        return Bitmap.createBitmap(toTransform, 0, 0, toTransform.getWidth(), toTransform.getHeight(), matrix, true);

        //return null;
    }

    @Override
    public String getId() {
        return rotateRotationAngle+"";
    }
}


Glide 加载:

Glide.with(this).load(imagePath).transform(new RotateTransformation(this,90)).into(imageView);

这样图片就会旋转90度显示。



你可能感兴趣的:(Glide,Android,效率开发)