Java tutorial
//package com.java2s; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; public class Main { /** * 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); } }