Java tutorial
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import android.graphics.Bitmap; import android.util.Log; public class Main { /** * Convert a bitmap to a byte array * @param path the path to the picture on the phone * @return the image in a byte array */ public static byte[] picToByte(Bitmap bitmap) { if (bitmap == null) { return null; } ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 10, baos); byte[] ba = baos.toByteArray(); try { baos.close(); } catch (IOException e) { Log.e("Error", "Error closing output stream" + e.getMessage()); return null; } return ba; } }