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.BitmapFactory;

import android.util.Log;

public class Main {
    public static Bitmap getBitmap(String path, BitmapFactory.Options options, float maxH, float maxW) {
        Bitmap cameraBitmap = null;
        int be = 1;
        float maxh = (int) ((maxH / 100.0) + 0.5) * 100;
        float maxw = (int) ((maxW / 100.0) + 0.5) * 100;
        Log.e("maxh", maxh + "");
        Log.e("maxw", maxw + "");
        options.inJustDecodeBounds = true;
        cameraBitmap = BitmapFactory.decodeFile(path, options);
        options.inJustDecodeBounds = false;
        int h = options.outHeight;
        int w = options.outWidth;
        Log.e("h", h + "");
        Log.e("w", w + "");
        if (h > maxh || w > maxw) {
            int beh = (int) ((h / maxh) + 0.5);
            int bew = (int) ((w / maxw) + 0.5);
            Log.e("beh", beh + "");
            Log.e("bew", bew + "");
            if (beh > bew) {
                be = beh;
            } else {
                be = bew;
            }
        }
        options.inSampleSize = be;
        cameraBitmap = BitmapFactory.decodeFile(path, options);
        return cameraBitmap;
    }
}