public static byte [ ] toBytes ( Bitmap bitmap , CompressFormat format , int quality ) throws IOException { byte [ ] bytes = null ; ByteArrayOutputStream byteStream = new ByteArrayOutputStream ( ) ; try { bitmap . compress ( format , quality , byteStream ) ; bytes = byteStream . toByteArray ( ) ; } finally { byteStream . close ( ) ; } return bytes ; }
Compress the bitmap to a byte array