Java tutorial
//package com.java2s; //License from project: Apache License import android.graphics.Bitmap; import java.io.ByteArrayOutputStream; import java.io.IOException; public class Main { /** * Method to convert a Bitmap into a byte[]. * Attention: this method is very expensive!!! * * @param source The Bitmap to convert. * @return The byte[] that represents the source Bitmap. */ public static byte[] toByteArray(Bitmap source) throws IOException { ByteArrayOutputStream blob = new ByteArrayOutputStream(); source.compress(Bitmap.CompressFormat.PNG, 0 /*ignored for PNG*/, blob); byte[] photoByteArray = blob.toByteArray(); blob.close(); return photoByteArray; } }