解码Android上的一块Bitmap

时间:2014-03-20 15:43:00

标签: android out-of-memory decode android-bitmap

我有OutOfMemoryError使用Android。 我有一个1000x1000位图和10个精灵图像。 (每张图片为100x100)

我只能加载一部分(100x100)位图?

BitmapFactory.decodeResource()生成OutOfMemoryError,因为我必须加载整个位图。我只需要100x100。

1 个答案:

答案 0 :(得分:1)

尝试使用BitmapRegionDecoder

实施例

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