本文介绍了如何使用滑行库旋转图像? (就像毕加索一样)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用滑行库旋转图像.以前,我可以使用毕加索(由于问题,我转而滑行).现在我在滑行中缺少旋转功能.我尝试使用转换,但没有用.
I am trying to rotate the image using glide library. Previously, was able to do with Picasso (due to an issue, I moved to glide). Now I am missing rotate functionality in glide. I tried using transformations but didn't work.
//使用的代码
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);
谢谢.
推荐答案
也许您已经找到了自己的解决方案,如果没有,也许对您有帮助.我使用此代码片段来旋转从相机获取的图像.
Maybe you found a solution already by yourself, if not, maybe this could help you. I use this snippet for rotate images which I get from the camera.
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中的公共常量
for more cases or exif int values, check the public constants in android.media.ExifInterface
这篇关于如何使用滑行库旋转图像? (就像毕加索一样)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!