Java tutorial
//package com.java2s; import android.graphics.Bitmap; import java.io.ByteArrayOutputStream; public class Main { public static byte[] Bitmap2Bytes(Bitmap bm, int ratio) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.JPEG, ratio, baos); //add if (bm != null && !bm.isRecycled()) { bm.recycle(); bm = null; } return baos.toByteArray(); } }