我正在尝试使用glide库旋转图像。之前,我可以和毕加索一起做(由于一个问题,我搬到了glide)。现在我在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
Glide.with(context)
.load(link)
.asBitmap()
.transform(new MyTransformation(context, 90))
.into(imageView);
提前谢谢。
发布于 2016-01-27 20:51:33
也许你已经找到了自己的解决方案,如果没有,也许这会对你有所帮助。我使用这个片段来旋转我从相机中获得的图像。
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中的公共常量
发布于 2018-05-09 00:02:04
我发现的一种方法是这样的。
Glide.with(mCtx)
.load(uploadImage.getImageUrl())
.into(holder.imageView);
holder.imageView.setRotation(uploadImage.getmRotation());
我希望你能理解。只需获取放入.into(x)
方法中的文件,然后编写x.setRotaion()
https://stackoverflow.com/questions/34811415
复制相似问题