如果我有一个通常会产生“内存不足”异常的大位图文件,我如何将它作为图 block 加载?例如我有一张 10,000x10,000 的图像,我想将其拆分为 10x10 的 1,000x1,000 像素图 block 网格。
我看过函数 Bitmap.createBitmap(sourceBitmap, x, y, width, height)
但它需要我的大图像作为源输入。
如何在不完全加载输入图像的情况下从我的输入图像中获取图 block ?
最佳答案
Romain Guy 在 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 :)
关于java - 如何从 Android 中的大位图中加载图 block ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4753013/