Code example for ByteArrayOutputStream

Methods: close, toByteArray

0
        pix.recycle();
    } 
 
    @SmallTest 
    public void testReadMem() throws IOException { 
        ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
        Bitmap bmp = Bitmap.createBitmap(640, 480, Bitmap.Config.RGB_565);
        bmp.compress(CompressFormat.JPEG, 85, byteStream);
        byte[] encodedData = byteStream.toByteArray();
        Pix pix = ReadFile.readMem(encodedData);
 
        assertEquals(bmp.getWidth(), pix.getWidth());
        assertEquals(bmp.getHeight(), pix.getHeight());
 
        // TODO(alanv): Need some way to test content, ex. Pix.getPixel(int, int) 
 
        byteStream.close();
        bmp.recycle();
        encodedData = null;
        pix.recycle();
    } 
}