Here are the test functions:
void decodeResource() { Bitmap originalBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.tile, null); originalBitmap.recycle(); }
void decodeStream() { InputStream ins = null; try { ins = getAssets().open("tile.png"); Bitmap originalBitmap = BitmapFactory.decodeStream(ins); originalBitmap.recycle(); } catch (final IOException e) { e.printStackTrace(); } finally { if (ins != null) try { ins.close(); } catch (IOException e) { } } }
Running both functions 50 times to load a small PNG file (230*230) on Nexus Galaxy running Android 4.2.2:
- decodeResource: 1793ms
- decodeStream: 188ms