Android Bitmap Rotate rotate(Bitmap bitmap, int degrees)

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

Description

Rotates the bitmap by the specified degree.

Parameter

Parameter Description
bitmap bitmap for rotating
degrees a parameter

Return

new bitmap

Declaration

public static Bitmap rotate(Bitmap bitmap, int degrees) 

Method Source Code

//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.Matrix;

public class Main {
    /**//from  www .j av  a2 s  .  co  m
     * Rotates the bitmap by the specified degree. </br>
     * If a new bitmap is created, the original bitmap is recycled.
     * @param bitmap bitmap for rotating
     * @param degrees
     * @return new bitmap
     */
    public static Bitmap rotate(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();
                    bitmap = b2;
                }
            } catch (OutOfMemoryError ex) {
                // We have no memory to rotate. Return the original bitmap.
            }
        }
        return bitmap;
    }
}

Related

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