Here you can find the source of saveToLocal(Bitmap bmp, String fileName)
Parameter | Description |
---|---|
bmp | the bmp |
fileName | the file name |
Parameter | Description |
---|---|
IOException | Signals that an I/O exception has occurred. |
public static String saveToLocal(Bitmap bmp, String fileName) throws IOException
//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(); } }