Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * This is the source code of DMPLayer for Android v. 1.0.0.
 * You should have received a copy of the license in this archive (see LICENSE).
 * Copyright @Dibakar_Mistry, 2015.
 */

import android.graphics.Bitmap;

import java.io.File;

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

public class Main {
    public static void saveBitmap(Bitmap btm, final String destDir, final String name) {
        File dir = new File(destDir);
        File file = new File(destDir + "/" + name + ".png");

        FileOutputStream out = null;
        try {
            if (!dir.mkdirs() && (!dir.exists() || !dir.isDirectory())) {
                throw new IOException("Cannot ensure parent directory for file " + file);
            }

            out = new FileOutputStream(file);
            btm.compress(Bitmap.CompressFormat.PNG, 100, out);
            // PNG is a lossless format, the compression factor (100) is ignored
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (out != null) {
                    out.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}