How to rotate an image using a slide library? (Like in Picasso)

I am trying to rotate an image using the planing library. I used to be able to do with Picasso (due to a problem, I moved to slide). Now I do not have the rotate function in glide. I tried to use transforms but did not work.

// Used code

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); 

Thanks in advance.

+3
source share
2 answers

Perhaps you have found a solution on your own, if not, maybe this can help you. I use this snippet to rotate the images that 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; //more cases default: exifInt = ExifInterface.ORIENTATION_NORMAL; break; } return exifInt; } 

and how to use it:

  Glide.with(mContext) .load(//your url) .asBitmap() .centerCrop() .transform(new MyTransformation(mContext, 90)) .diskCacheStrategy(DiskCacheStrategy.RESULT) .into(//your view); 

for more cases or exif int values, check the public constants in android.media.ExifInterface

+10
source

One way to find this.

 Glide.with(mCtx) .load(uploadImage.getImageUrl()) .into(holder.imageView); holder.imageView.setRotation(uploadImage.getmRotation()); 

I hope you understand. Just take the file that you put inside the .into(x) method and then write x.setRotaion()

0
source

All Articles