Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.File;

import java.io.FileOutputStream;

import android.content.Context;
import android.content.ContextWrapper;

import android.graphics.Bitmap;

public class Main {
    public static String saveToInternalSorage(Bitmap bitmapImage, String filename, Context context) {
        File mypath = new File(getImagesDirectory(context), filename);
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(mypath);
            bitmapImage.compress(Bitmap.CompressFormat.JPEG, 100, fos);
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return mypath.getAbsolutePath();
    }

    public static File getImagesDirectory(Context context) {
        ContextWrapper cw = new ContextWrapper(context);
        File directory = cw.getDir("images", Context.MODE_PRIVATE);
        return directory;
    }
}