Java tutorial
//package com.java2s; import android.graphics.Bitmap; import java.nio.ByteBuffer; public class Main { public static byte[] bitmapToByteArray(Bitmap bitmap) { //int numBytes = bitmap.getWidth() + bitmap.getHeight() * 4; int numBytes = bitmap.getByteCount(); ByteBuffer byteBuffer = ByteBuffer.allocate(numBytes); bitmap.copyPixelsToBuffer(byteBuffer); return byteBuffer.array(); } }