How to load tiles from a large bitmap in Android?

Answer from Romain Guy in Is it possible to chop a bitmap to small pieces without loading the entire thing into memory?:

Android 2.3.3 has a new API called
android.graphics.BitmapRegionDecoder
that lets you do exactly what you
want.

You would for instance do the
following:

BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(myStream, false);  
Bitmap region = decoder.decodeRegion(new Rect(10, 10, 50, 50), null);

Easy 🙂

Leave a Comment