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 java.io.*;

public class Main {

    public static boolean putBitmapToFile(Bitmap bitmap, File file) {
        if (bitmap == null || file == null)
            return false;
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
            return true;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } finally {
            if (fos != null)
                try {
                    fos.flush();
                    fos.close();
                    if (!bitmap.isRecycled())
                        bitmap.recycle();
                } catch (IOException ignored) {
                }
        }
        return false;
    }
}