我使用的是懒惰加载程序示例,但我的应用程序在Logcat中给出了以下错误。
12-14 15:27:55.987: E/dalvikvm-heap(27566): 2457600-byte external allocation too large for this process.
12-14 15:27:55.992: E/(27566): VM won't let us allocate 2457600 bytes
12-14 15:27:55.992: D/skia(27566): --- decoder->decode returned false
我在写时使用Imageloader类
private Bitmap decodeFile(File f){
try {
//decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
o.inPurgeable = true; // Tell to garbage collector that whether it needs free memory, the Bitmap can be cleared
o.inTempStorage = new byte[32 * 1024];
BitmapFactory.decodeStream(new FileInputStream(f),null,o);
//Find the correct scale value. It should be the power of 2.
final int REQUIRED_SIZE=70;
int width_tmp=o.outWidth, height_tmp=o.outHeight;
int scale=1;
while(true){
if(width_tmp/2<REQUIRED_SIZE || height_tmp/2<REQUIRED_SIZE)
break;
width_tmp/=2;
height_tmp/=2;
scale*=2;
}
//decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inPurgeable = true; // Tell to garbage collector that whether it needs free memory, the Bitmap can be cleared
o2.inTempStorage = new byte[32 * 1024];
o2.inSampleSize=scale;
Bitmap bitmap1=BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
// System.out.println("width : "+bitmap1.getWidth()+ " height : "+bitmap1.getHeight());
/* if(bitmap1.getHeight()>=bitmap1.getWidth())
{
bitmap1 = Bitmap.createScaledBitmap(bitmap1, bitmap1.getHeight(),bitmap1.getWidth(), true);
}else{
//bmp = Bitmap.createScaledBitmap(bmp, (int) height2,width, true);
Matrix matrix = new Matrix();
matrix.postRotate(270);
bitmap1 = Bitmap.createBitmap(bitmap1 , 0, 0, bitmap1 .getWidth(), bitmap1 .getHeight(), matrix, true);
}*/
return bitmap1;
} catch (FileNotFoundException e) {}
return null;
}
但我使用sacle=scale*1,因为我想要使用scale-scale*2的高清图像,然后我的图像像模糊一样。。
那我该怎么办?
我建议您使用Picasso库。它比Android通用图像加载器更简单,但功能同样强大。
您不需要做所有这些。试试这个图书馆。这太棒了。Android通用图像加载器