Code example for ByteArrayOutputStream

Methods: toByteArray

     * We can't just store and exit, because Android freezes up when we try to cram a picture across a process in a Bundle. 
     * We HAVE to compress this data and send back the compressed data   
    public void storeAndExit(byte[] data)
    	ByteArrayOutputStream jpeg_data = new ByteArrayOutputStream();
		Bitmap myMap = BitmapFactory.decodeByteArray(data, 0, data.length);
		try { 
			if (myMap.compress(CompressFormat.JPEG, quality, jpeg_data))
				byte[] code  = jpeg_data.toByteArray();
				byte[] output = Base64.encodeBase64(code);
				String js_out = new String(output);
				mIntent.putExtra("picture", js_out);
				setResult(RESULT_OK, mIntent);
		catch(Exception e)
			//Do shit here 
Contextual code suggestions in your IDE  Get Codota for Java