ByteBuffer way of converting Java bitmap to byte array
int size = bitmap.getRowBytes() * bitmap.getHeight();
ByteBuffer byteBuffer = ByteBuffer.allocate(size);
bitmap.copyPixelsToBuffer(byteBuffer);
byte[] byteArray = byteBuffer.array();
// Save and later load these:
int width = bitmap.getWidth();
int height = bitmap.getHeight();
String format = bitmap.getConfig().name();
Byte-array to Bitmap
Bitmap.Config configBmp = Bitmap.Config.valueOf(format);
Bitmap bitmap_tmp = Bitmap.createBitmap(width, height, configBmp);
ByteBuffer buffer = ByteBuffer.wrap(byteArray);
bitmap_tmp.copyPixelsFromBuffer(buffer);