Android Bitmap Rotate getRotatedBitmap(Bitmap bitmap, int degrees)

Here you can find the source of getRotatedBitmap(Bitmap bitmap, int degrees)

Description

get Rotated Bitmap

Declaration

public static Bitmap getRotatedBitmap(Bitmap bitmap, int degrees) 

Method Source Code

//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.Matrix;

public class Main {
    public static Bitmap getRotatedBitmap(Bitmap bitmap, int degrees) {
        if (degrees != 0 && bitmap != null) {
            Matrix m = new Matrix();
            m.setRotate(degrees, (float) bitmap.getWidth() / 2,
                    (float) bitmap.getHeight() / 2);
            try {
                Bitmap b2 = Bitmap.createBitmap(bitmap, 0, 0,
                        bitmap.getWidth(), bitmap.getHeight(), m, true);
                if (bitmap.equals(b2)) {
                    bitmap.recycle();/* ww w  .j a va 2  s .co m*/
                    bitmap = b2;
                }
            } catch (OutOfMemoryError ex) {
                // TODO Auto-generated catch block
                ex.printStackTrace();
            }
        }
        return bitmap;
    }
}

Related

  1. rotateBitmap(Bitmap bitmap, float degrees)
  2. rotateBitmap(Bitmap input, int degrees)
  3. rotateBitmapTranslate(Bitmap bitmap, float degrees)
  4. rotateBitmap(Bitmap source, int rotation, boolean recycle)
  5. rotateBitmap(Bitmap b, int degrees)
  6. rotateBitmap(Bitmap bitmap, float degrees)
  7. rotateBitmapTranslate(Bitmap bitmap, float degrees)
  8. createRotatedBitmap(Bitmap bm, float degree)
  9. RotateBitmap(Bitmap source, float angle)