Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.InputStream;
import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

import android.util.Log;

public class Main {

    public static Bitmap getCompressedBitmap(String filePath, int sampleSize) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = sampleSize;
        try {
            return BitmapFactory.decodeFile(filePath, options);
        } catch (OutOfMemoryError e) {
            Log.e("talktab.error", "OutOfMemoryError");
            options.inSampleSize = sampleSize * 2;
            return BitmapFactory.decodeFile(filePath, options);
        }
    }

    public static Bitmap getCompressedBitmap(InputStream is, int sampleSize) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = sampleSize;
        try {
            return BitmapFactory.decodeStream(is, null, options);
        } catch (OutOfMemoryError e) {
            Log.e("talktab.error", "OutOfMemoryError");
            options.inSampleSize = sampleSize * 2;
            return BitmapFactory.decodeStream(is, null, options);
        }
    }
}