public static byte[] toByteArray(Bitmap bitmap,Bitmap.CompressFormat format,int quality){
  ByteArrayOutputStream out=null;
  try {
    out=new ByteArrayOutputStream();
    bitmap.compress(format,quality,out);
    return out.toByteArray();
  }
  finally {
    CloseableUtils.close(out);
  }
}

public static byte [ ] toByteArray ( Bitmap bitmap , Bitmap . CompressFormat format , int quality ) { ByteArrayOutputStream out = null ; try { out = new ByteArrayOutputStream ( ) ; bitmap . compress ( format , quality , out ) ; return out . toByteArray ( ) ; } finally { CloseableUtils . close ( out ) ; } }
compress the bitmap to the byte array as the specified format and quality .
