summaryrefslogtreecommitdiff
path: root/java/com/android/contacts/common/util/BitmapUtil.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/com/android/contacts/common/util/BitmapUtil.java')
-rw-r--r--java/com/android/contacts/common/util/BitmapUtil.java26
1 files changed, 26 insertions, 0 deletions
diff --git a/java/com/android/contacts/common/util/BitmapUtil.java b/java/com/android/contacts/common/util/BitmapUtil.java
index 51f65f280..20f916a3f 100644
--- a/java/com/android/contacts/common/util/BitmapUtil.java
+++ b/java/com/android/contacts/common/util/BitmapUtil.java
@@ -24,6 +24,8 @@ import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
/** Provides static functions to decode bitmaps at the optimal size */
public class BitmapUtil {
@@ -89,6 +91,30 @@ public class BitmapUtil {
}
/**
+ * Retrieves a copy of the specified drawable resource, rotated by a specified angle.
+ *
+ * @param resources The current resources.
+ * @param resourceId The resource ID of the drawable to rotate.
+ * @param angle The angle of rotation.
+ * @return Rotated drawable.
+ */
+ public static Drawable getRotatedDrawable(
+ android.content.res.Resources resources, int resourceId, float angle) {
+
+ // Get the original drawable and make a copy which will be rotated.
+ Bitmap original = BitmapFactory.decodeResource(resources, resourceId);
+ Bitmap rotated =
+ Bitmap.createBitmap(original.getWidth(), original.getHeight(), Bitmap.Config.ARGB_8888);
+
+ // Perform the rotation.
+ Canvas tempCanvas = new Canvas(rotated);
+ tempCanvas.rotate(angle, original.getWidth() / 2, original.getHeight() / 2);
+ tempCanvas.drawBitmap(original, 0, 0, null);
+
+ return new BitmapDrawable(resources, rotated);
+ }
+
+ /**
* Given an input bitmap, scales it to the given width/height and makes it round.
*
* @param input {@link Bitmap} to scale and crop