Android Bitmap Save saveToLocal(Bitmap bmp, String fileName)

Here you can find the source of saveToLocal(Bitmap bmp, String fileName)

Description

Save to local.

Parameter

Parameter Description
bmp the bmp
fileName the file name

Exception

Parameter Description
IOException Signals that an I/O exception has occurred.

Return

the absolute path of saved file

Declaration

public static String saveToLocal(Bitmap bmp, String fileName)
        throws IOException 

Method Source Code

//package com.java2s;

import java.io.ByteArrayOutputStream;
import java.io.File;

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

import android.graphics.Bitmap;

import android.os.Environment;

public class Main {
    /**//from  w  ww.j a  v a  2 s .  c  o  m
     * Save to local.
     *
     * @param bmp the bmp
     * @param fileName the file name
     * @return the absolute path of saved file
     * @throws IOException Signals that an I/O exception has occurred.
     */
    public static String saveToLocal(Bitmap bmp, String fileName)
            throws IOException {
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        bmp.compress(Bitmap.CompressFormat.JPEG, 100, bytes);

        File f = new File(Environment.getExternalStorageDirectory()
                + File.separator + fileName);
        f.createNewFile();
        FileOutputStream fo = new FileOutputStream(f);
        fo.write(bytes.toByteArray());

        fo.close();
        return "" + f.getAbsolutePath();
    }
}

Related

  1. saveBitmapFromScrollView(ScrollView scrollView, String path)
  2. saveBitmaptoFile(Bitmap bmp, String path, CompressFormat format, int quality)
  3. saveImage(String filename, Bitmap bm)
  4. saveImage(String filename, Bitmap bm, boolean landscape)
  5. saveMyBitmap(String bitName, Bitmap mBitmap)
  6. storeImage(Context context, Bitmap image)
  7. saveBitmap(Bitmap bitmap, String filename)
  8. saveBitmap2SD(Bitmap bitmap, Context context, String filePath, String fileName)
  9. addImageAsApplication(ContentResolver cr, String name, long dateTaken, String directory, String filename, Bitmap source, byte[] jpegData)