mirror Bitmap And Recycle - Android Graphics

Android examples for Graphics:Bitmap Recycle

Description

mirror Bitmap And Recycle

Demo Code


//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.Matrix;

public class Main {
    public static Bitmap mirrorAndRecycle(Bitmap b) {
        if (b != null) {
            Matrix m = new Matrix();

            m.setScale(-1, 1);/*from www .ja va  2s .  c  o m*/
            m.postTranslate(b.getWidth(), 0);

            try {
                Bitmap b2 = Bitmap.createBitmap(b, 0, 0, b.getWidth(),
                        b.getHeight(), m, true);
                if (b != b2) {
                    b.recycle();
                    b = b2;
                    System.gc();
                    System.gc();
                }
            } catch (OutOfMemoryError ex) {
                throw ex;
            }
        }
        return b;
    }
}

Related Tutorials