Skip to content Skip to sidebar Skip to footer

How To Rotate Image Using Glide Library? (like In Picasso)

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

Solution 1:

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.

publicMyTransformation(Context context, int orientation) {
    super(context);
    mOrientation = orientation;
}

@Overrideprotected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
    intexifOrientationDegrees= getExifOrientationDegrees(mOrientation);
    return TransformationUtils.rotateImageExif(toTransform, pool, exifOrientationDegrees);
}

privateintgetExifOrientationDegrees(int orientation) {
    int exifInt;
    switch (orientation) {
        case90:
            exifInt = ExifInterface.ORIENTATION_ROTATE_90;
            break;
        // other casesdefault:
            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

Solution 2:

One way I found was 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()

Post a Comment for "How To Rotate Image Using Glide Library? (like In Picasso)"