Rav*_*udi 6 android android-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);
}
}
Run Code Online (Sandbox Code Playgroud)
//滑翔
Glide.with(context)
.load(link)
.asBitmap()
.transform(new MyTransformation(context, 90))
.into(imageView);
Run Code Online (Sandbox Code Playgroud)
提前致谢.
小智 17
也许你已经找到了自己的解决方案,如果没有,也许这可以帮助你.我使用这个片段来旋转从相机中获取的图像.
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;
}
Run Code Online (Sandbox Code Playgroud)
以及如何使用它:
Glide.with(mContext)
.load(//your url)
.asBitmap()
.centerCrop()
.transform(new MyTransformation(mContext, 90))
.diskCacheStrategy(DiskCacheStrategy.RESULT)
.into(//your view);
Run Code Online (Sandbox Code Playgroud)
对于更多case或exif int值,检查android.media.ExifInterface中的公共常量
小智 10
我发现的一种方法是这样。
Glide.with(mCtx)
.load(uploadImage.getImageUrl())
.into(holder.imageView);
holder.imageView.setRotation(uploadImage.getmRotation());
Run Code Online (Sandbox Code Playgroud)
我希望你明白。只需取出您放入.into(x)方法中的文件,然后编写x.setRotaion()
| 归档时间: |
|
| 查看次数: |
8422 次 |
| 最近记录: |