Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.graphics.Bitmap;

import android.media.ThumbnailUtils;

public class Main {
    public static Bitmap extractBitmap(Bitmap source, int width, int height) {
        if (!checkBitmap(source)) {
            return null;
        }
        return ThumbnailUtils.extractThumbnail(source, width, height);
    }

    public static Bitmap extractBitmap(Bitmap source, float scale) {
        if (null == source) {
            return null;
        }
        Bitmap dest = Bitmap.createScaledBitmap(source, (int) (source.getWidth() * scale),
                (int) (source.getHeight() * scale), false);
        recycle(source);
        return dest;
    }

    public static boolean checkBitmap(Bitmap bitmap) {
        if (null == bitmap || bitmap.isRecycled() || bitmap.getWidth() <= 0 || bitmap.getHeight() <= 0) {
            return false;
        }
        return true;
    }

    public static void recycle(Bitmap bitmap) {
        if (null == bitmap || bitmap.isRecycled()) {
            return;
        }
        bitmap.recycle();
    }
}