Code example for ByteArrayOutputStream

Methods: close, toByteArray

0
        if (pixs == null)
            throw new IllegalArgumentException("Source pix must be non-null");
        if (quality < 0 || quality > 100)
            throw new IllegalArgumentException("Quality must be between 0 and 100 (inclusive)");
 
        final ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
        final Bitmap bmp = WriteFile.writeBitmap(pixs);
        bmp.compress(CompressFormat.JPEG, quality, byteStream);
        bmp.recycle();
 
        final byte[] encodedData = byteStream.toByteArray();
 
        try { 
            byteStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        } 
 
        return encodedData;
    }