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.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import android.graphics.Bitmap;

import android.os.Environment;

public class Main {
    public static void saveWeiboBitmap(Bitmap bitmap, String filename) {
        String status = Environment.getExternalStorageState();
        if (bitmap == null || !status.equals(Environment.MEDIA_MOUNTED)) {
            return;
        }
        File f = new File(filename);
        FileOutputStream fOut = null;
        boolean error = false;
        try {
            f.createNewFile();
        } catch (IOException e1) {
            e1.printStackTrace();
            error = true;
        }

        try {
            fOut = new FileOutputStream(f);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            error = true;
        }

        try {
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
        } catch (Exception e) {
            e.printStackTrace();
            error = true;
        }

        try {
            fOut.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            fOut.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}