Android Bitmap Save save(Bitmap bitmap, String fileName)

Here you can find the source of save(Bitmap bitmap, String fileName)

Description

save

Declaration

public static String save(Bitmap bitmap, String fileName) 

Method Source Code

//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 final String SDCARD_FOLDER = "eventmanager";

    public static String save(Bitmap bitmap, String fileName) {
        File folder = new File(Environment.getExternalStorageDirectory(),
                SDCARD_FOLDER);/* w w  w . ja va 2s .com*/
        if (!folder.exists() && !folder.mkdirs()) {
            //Log.w(TAG, "Couldn't make dir " + barcodesRoot);
            //showErrorMessage(R.string.msg_unmount_usb);
            folder = new File(Environment.getDataDirectory(), SDCARD_FOLDER);
        }
        File barcodeFile = new File(folder, fileName + ".png");
        barcodeFile.delete();
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(barcodeFile);
            bitmap.compress(Bitmap.CompressFormat.PNG, 0, fos);
            return barcodeFile.getAbsolutePath();
        } catch (FileNotFoundException fnfe) {
            //Log.w(TAG, "Couldn't access file " + barcodeFile + " due to " + fnfe);
            //showErrorMessage(R.string.msg_unmount_usb);
            return "";
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException ioe) {
                    // do nothing
                }
            }
        }
    }
}

Related

  1. storeImage(Context context, Bitmap image)
  2. saveBitmap(Bitmap bitmap, String filename)
  3. saveBitmap2SD(Bitmap bitmap, Context context, String filePath, String fileName)
  4. addImageAsApplication(ContentResolver cr, String name, long dateTaken, String directory, String filename, Bitmap source, byte[] jpegData)
  5. saveBitmapToFile(Bitmap bitmap, String path)
  6. saveBitmapToFile(Bitmap bitmap, String filename)
  7. saveBitmap(Bitmap bmp, String path, CompressFormat format)
  8. saveBitmap(Bitmap image)
  9. saveBitmap(File file, Bitmap bitmap)