Java tutorial
//package com.java2s; import android.graphics.Bitmap; import java.io.ByteArrayOutputStream; public class Main { public static byte[] bmpToByteArray(Bitmap bitmap, boolean flag) { ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(); bitmap.compress(android.graphics.Bitmap.CompressFormat.JPEG, 100, bytearrayoutputstream); if (flag) bitmap.recycle(); byte abyte0[] = bytearrayoutputstream.toByteArray(); try { bytearrayoutputstream.close(); } catch (Exception exception) { exception.printStackTrace(); } return abyte0; } }