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.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;

public class Main {
    public static Bitmap decodeFileRestrictDataSize(String path, int maxDataSize) {
        Options options = getBitmapOptionsWithSize(path);
        int width = options.outWidth;
        int height = options.outHeight;
        int scale = 1;
        while (width * height * 4 > maxDataSize) {
            scale *= 2;
            width /= 2;
            height /= 2;
        }
        options.inSampleSize = scale;
        return BitmapFactory.decodeFile(path, options);
    }

    public static Options getBitmapOptionsWithSize(String path) {
        Options options = new Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(path, options);
        options.inJustDecodeBounds = false;
        return options;
    }
}