Java tutorial
//package com.java2s; //License from project: Apache License import android.graphics.Bitmap; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { public static boolean bitmapToOutPutStream(final Bitmap bitmap, OutputStream outputStream) { BufferedOutputStream out = null; BufferedInputStream in = null; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); InputStream inputStream = new ByteArrayInputStream(baos.toByteArray()); in = new BufferedInputStream(inputStream, 8 * 1024); out = new BufferedOutputStream(outputStream, 8 * 1024); int b; while ((b = in.read()) != -1) { out.write(b); } return true; } catch (IOException e) { e.printStackTrace(); } finally { try { if (out != null) { out.close(); } if (in != null) { in.close(); } } catch (final IOException e) { e.printStackTrace(); } } return false; } }