How to load tiles from a large bitmap in Android?
26,811
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 :)
Author by
Adam McKee
Updated on July 09, 2022Comments
-
Adam McKee almost 2 years
If I have a large bitmap file that would normally generate an "Out of memory" exception, how can I load it as tiles? e.g. I have a 10,000x10,000 image, I want to split it up into a 10x10 grid of 1,000x1,000 pixel tiles.
I've seen the function
Bitmap.createBitmap(sourceBitmap, x, y, width, height)
but it requires my large image as the source input.How can I get a tile from my input image, without fully loading the input image?
-
Adam McKee over 13 yearsHi, thanks for that, unfortunately I won't have any control over the images that are used with the application.