get Rotate Drawable - Android Graphics

Android examples for Graphics:Drawable Operation

Description

get Rotate Drawable

Demo Code


//package com.java2s;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

public class Main {
    public static Drawable getRotateDrawable(Resources res,
            final Bitmap bitmap, final float angle) {
        final BitmapDrawable drawable = new BitmapDrawable(res, bitmap) {
            @Override/*  w w  w  . ja v a  2 s  .  c  o m*/
            public void draw(final Canvas canvas) {
                canvas.save();
                canvas.rotate(angle, bitmap.getWidth() / 2,
                        bitmap.getHeight() / 2);
                super.draw(canvas);
                canvas.restore();
            }
        };
        return drawable;
    }
}

Related Tutorials