Java tutorial
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import android.graphics.Bitmap; public class Main { public static boolean saveBitmap(Bitmap aBmp, String aPath) { if (aBmp == null || aPath == null) { return false; } FileOutputStream fos = null; ByteArrayOutputStream baos = null; boolean result; try { File file = new File(aPath); if (!file.exists()) { file.createNewFile(); } fos = new FileOutputStream(file); baos = new ByteArrayOutputStream(); aBmp.compress(Bitmap.CompressFormat.PNG, 100, baos); //SUPPRESS CHECKSTYLE fos.write(baos.toByteArray()); baos.flush(); fos.flush(); result = true; } catch (OutOfMemoryError e) { e.printStackTrace(); result = false; } catch (Exception e) { e.printStackTrace(); result = false; } finally { try { if (baos != null) { baos.close(); } if (fos != null) { fos.close(); } } catch (IOException e) { e.printStackTrace(); } } return result; } }