-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BitmapTransformation to rotate the image (#3444)
* Added BitmapTransformation for rotation * Improved override methods
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
library/src/main/java/com/bumptech/glide/load/resource/bitmap/Rotate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.bumptech.glide.load.resource.bitmap; | ||
|
||
import android.graphics.Bitmap; | ||
import android.support.annotation.NonNull; | ||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; | ||
import com.bumptech.glide.util.Util; | ||
import java.nio.ByteBuffer; | ||
import java.security.MessageDigest; | ||
|
||
/** | ||
* A {@link BitmapTransformation} which rotates the bitmap. | ||
*/ | ||
public class Rotate extends BitmapTransformation { | ||
private static final String ID = "com.bumptech.glide.load.resource.bitmap.Rotate"; | ||
private static final byte[] ID_BYTES = ID.getBytes(CHARSET); | ||
|
||
private final int degreesToRotate; | ||
|
||
/** | ||
* @param degreesToRotate number of degrees to rotate the image by. If zero the original image is | ||
* not modified. | ||
*/ | ||
public Rotate(int degreesToRotate) { | ||
this.degreesToRotate = degreesToRotate; | ||
} | ||
|
||
@Override | ||
protected Bitmap transform( | ||
@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) { | ||
return TransformationUtils.rotateImage(toTransform, degreesToRotate); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (o instanceof Rotate) { | ||
Rotate other = (Rotate) o; | ||
return degreesToRotate == other.degreesToRotate; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Util.hashCode(ID.hashCode(), | ||
Util.hashCode(degreesToRotate)); | ||
} | ||
|
||
@Override | ||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { | ||
messageDigest.update(ID_BYTES); | ||
|
||
byte[] degreesData = ByteBuffer.allocate(4).putInt(degreesToRotate).array(); | ||
messageDigest.update(degreesData); | ||
} | ||
} |