错误加载图像gridview的机器人 [英] error in loading images to gridview android
本文介绍了错误加载图像gridview的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/1949066/java-lang-outofmemoryerror-bitmap-size-exceeds-vm-budget-android\">java.lang.OutOfMemoryError:位图大小超过VM预算 - Android电子
加载图像网格视图时,会出现以下错误。
the following error occur when loading images to grid view.
java.lang.OutOfMemoryError:位图的大小超过VM预算
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
请帮助我。有没有解决这个错误。
please help me. is there any solution to this error.
推荐答案
试试这个
public static Bitmap decodeFile(File f,int WIDTH,int HIGHT){
try {
//Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(new FileInputStream(f),null,o);
//The new size we want to scale to
final int REQUIRED_WIDTH=WIDTH;
final int REQUIRED_HIGHT=HIGHT;
//Find the correct scale value. It should be the power of 2.
int scale=1;
while(o.outWidth/scale/2>=REQUIRED_WIDTH && o.outHeight/scale/2>=REQUIRED_HIGHT)
scale*=2;
//Decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize=scale;
return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
}
catch (FileNotFoundException e) {}
return null;
}
这将扩大位图按照宽度和高度传递。
this will scale bitmap as per width and height you pass..
这篇关于错误加载图像gridview的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文