Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

import android.widget.ImageView;

public class Main {
    /**
     * <pre>
     * Recycle bitmap rendered by {@link ImageView}.
     * </pre>
     * @return true if bitmap was recycled successfully
     */
    public static boolean recycleImageView(ImageView imageView) {
        Bitmap bm = extractBitmap(imageView);
        imageView.setImageBitmap(null);
        return recycleBitmap(bm);
    }

    /**
     * <pre>
     * Extract {@link Bitmap} object rendered by {@link ImageView}
     * </pre>
     */
    public static Bitmap extractBitmap(ImageView imageView) {
        if (imageView == null)
            return null;
        Drawable drawable = imageView.getDrawable();
        if (drawable != null && drawable instanceof BitmapDrawable) {
            Bitmap bm = ((BitmapDrawable) drawable).getBitmap();
            return bm;
        }
        return null;
    }

    /**
     * <pre>
     * Recycle a {@link Bitmap} object
     * </pre>
     * @return true if bitmap was recycled successfully
     */
    public static boolean recycleBitmap(Bitmap bm) {
        if (bm != null && !bm.isRecycled()) {
            bm.recycle();
            return true;
        }
        return false;
    }
}