Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.content.Context;
import android.content.ContextWrapper;

import android.graphics.Bitmap;

import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;

public class Main {
    public static String saveToInternalStorage(Bitmap bitmap, String title, Context context) throws IOException {
        ContextWrapper cw = new ContextWrapper(context);
        File directory = cw.getDir("bitmaps", Context.MODE_PRIVATE);
        File image = new File(directory, title);
        FileOutputStream fileOutputStream = null;
        try {
            fileOutputStream = new FileOutputStream(image);
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            fileOutputStream.close();
        }
        return directory.getAbsolutePath();
    }
}