Java tutorial
//package com.java2s; //License from project: Apache License import android.graphics.Bitmap; import java.io.ByteArrayOutputStream; public class Main { private static byte[] bmpToByteArray(final Bitmap bmp, final boolean needRecycle) { ByteArrayOutputStream output = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 100, output); if (needRecycle) { bmp.recycle(); } byte[] result = output.toByteArray(); try { output.close(); } catch (Exception e) { } return result; } }