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 synchronized 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 synchronized 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 != b2) {
                    bitmap.recycle();/*from  w  w w . j a  v a2s  .  c om*/
                    bitmap = b2;
                }
            } catch (OutOfMemoryError ex) {
                // We have no memory to rotate. Return the original bitmap.
            }
        }

        return bitmap;
    }
}

Related

  1. rotateBitmap(Bitmap b, int degrees)
  2. rotateBitmap(Bitmap source, float angle)
  3. rotateBitmap(Bitmap source, int rotation, boolean recycle)
  4. rotatePic(Bitmap bitmap, int degree)
  5. rotation(Bitmap source, int degrees)
  6. computePictureRotation()
  7. GetExifOrientation(String filepath)
  8. reflectionFromBitmap(Bitmap originalBitmap, boolean isFuzzy)
  9. rotate(Bitmap bitmap, int angle)