Android Bitmap Rotate rotateBitmap(Bitmap source, int rotation, boolean recycle)

Here you can find the source of rotateBitmap(Bitmap source, int rotation, boolean recycle)

Description

rotate Bitmap

Declaration

public static Bitmap rotateBitmap(Bitmap source, int rotation,
            boolean recycle) 

Method Source Code

//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.Matrix;

public class Main {
    public static Bitmap rotateBitmap(Bitmap source, int rotation,
            boolean recycle) {
        if (rotation == 0)
            return source;
        int w = source.getWidth();
        int h = source.getHeight();
        Matrix m = new Matrix();
        m.postRotate(rotation);/*  w ww  .j  ava  2 s  .  c  om*/
        Bitmap bitmap = Bitmap.createBitmap(source, 0, 0, w, h, m, true);
        if (recycle)
            source.recycle();
        return bitmap;
    }

    public static Bitmap rotateBitmap(Bitmap b, int degrees) {
        if (degrees != 0 && b != null) {
            Matrix m = new Matrix();
            m.setRotate(degrees, (float) b.getWidth() / 2,
                    (float) b.getHeight() / 2);
            try {
                Bitmap b2 = Bitmap.createBitmap(b, 0, 0, b.getWidth(),
                        b.getHeight(), m, true);
                if (b != b2) {
                    b.recycle();
                    b = b2;
                }
            } catch (OutOfMemoryError ex) {
                // We have no memory to rotate. Return the original bitmap.
            }
        }
        return b;
    }
}

Related

  1. rotate(Bitmap bitmap, int angle)
  2. rotate(Bitmap bitmap, int degrees)
  3. rotateBitmap(Bitmap bitmap, float degrees)
  4. rotateBitmap(Bitmap input, int degrees)
  5. rotateBitmapTranslate(Bitmap bitmap, float degrees)
  6. rotateBitmap(Bitmap b, int degrees)
  7. getRotatedBitmap(Bitmap bitmap, int degrees)
  8. rotateBitmap(Bitmap bitmap, float degrees)
  9. rotateBitmapTranslate(Bitmap bitmap, float degrees)