Here you can find the source of bitmap2Stream(Bitmap bitmap, CompressFormat format, int quality)
public static final InputStream bitmap2Stream(Bitmap bitmap, CompressFormat format, int quality)
//package com.java2s; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; public class Main { public static final InputStream bitmap2Stream(Bitmap bitmap) { return bitmap2Stream(bitmap, CompressFormat.JPEG, 100); }/*from w w w .ja va 2 s .com*/ public static final InputStream bitmap2Stream(Bitmap bitmap, CompressFormat format, int quality) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(format, quality, baos); InputStream stream = new ByteArrayInputStream(baos.toByteArray()); return stream; } }