Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.File;

import android.content.Context;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

public class Main {
    public static synchronized Bitmap getTempBitmap(Context context, String filename) {
        File path = new File(getTempDirectory(context), filename);
        return decodeSampledBitmapFromFile(path.getAbsolutePath());
    }

    private static synchronized File getTempDirectory(Context context) {
        File tempDir = new File(context.getFilesDir(), "temps/");
        if (!tempDir.exists()) {
            tempDir.mkdirs();
        }
        return tempDir;
    }

    public static synchronized Bitmap decodeSampledBitmapFromFile(String path) {

        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 1;
        options.outMimeType = "image/jpeg";
        options.inDither = false;
        options.inPurgeable = true;
        options.inInputShareable = true;
        options.inPreferredConfig = Bitmap.Config.ARGB_8888;
        options.inTempStorage = new byte[256];

        return BitmapFactory.decodeFile(path, options);
    }
}