//使用以下方法有效解決讀圖產生的OOM問題
String imagePath = “/mnt/sdcard/Android/data/tw.lya/LocationMapTest/file.png";

//讀圖時要加下列這些
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
Bitmap mapImage = BitmapFactory.decodeFile(imagePath, options);

options.inJustDecodeBounds = false;
options.inSampleSize = 1;
mapImage = BitmapFactory.decodeFile(imagePath, options);

//當這張圖不需要時,要回收掉
if(bitmap != null && !bitmap.isRecycled()){
bitmap.recycle();
bitmap = null;
}
System.gc();

廣告