public static byte[] flattenBitmap(Bitmap bitmap){
  int size=bitmap.getWidth() * bitmap.getHeight() * 4;
  ByteArrayOutputStream out=new ByteArrayOutputStream(size);
  try {
    bitmap.compress(Bitmap.CompressFormat.PNG,100,out);
    out.flush();
    out.close();
    return out.toByteArray();
  }
 catch (  IOException e) {
    Log.w(TAG,"Could not write bitmap");
    return null;
  }
}

public static byte [ ] flattenBitmap ( Bitmap bitmap ) { int size = bitmap . getWidth ( ) * bitmap . getHeight ( ) * 4 ; ByteArrayOutputStream out = new ByteArrayOutputStream ( size ) ; try { bitmap . compress ( Bitmap . CompressFormat . PNG , 100 , out ) ; out . flush ( ) ; out . close ( ) ; return out . toByteArray ( ) ; } catch ( IOException e ) { Log . w ( TAG , "Could not write bitmap" ) ; return null ; } }
compresses the bitmap to a byte array for serialization .
