Code example for ByteArrayOutputStream

Methods: closetoByteArrayflush

     * Helper method to compress the given bitmap as a JPEG and return the resulting byte array. 
    private byte[] getCompressedBytes(Bitmap b, int quality) throws IOException {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final boolean compressed = b.compress(Bitmap.CompressFormat.JPEG, quality, baos);
        byte[] result = baos.toByteArray();
        if (!compressed) {
            throw new IOException("Unable to compress image");
        return result;
     * Retrieves the uncompressed display photo. 
Connect your IDE to all the code out there  Get Codota for Java