Here you can find the source of bmpToByteArray(final Bitmap bmp, final boolean needRecycle)
private static byte[] bmpToByteArray(final Bitmap bmp, final boolean needRecycle)
//package com.java2s; import java.io.ByteArrayOutputStream; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; public class Main { private static byte[] bmpToByteArray(final Bitmap bmp, final boolean needRecycle) { ByteArrayOutputStream output = new ByteArrayOutputStream(); bmp.compress(CompressFormat.JPEG, 60, output); if (needRecycle) { bmp.recycle();//from w w w .j a va 2 s .co m } byte[] result = output.toByteArray(); try { output.close(); } catch (Exception e) { e.printStackTrace(); } return result; } }