Error In Loading Images To Gridview Android
Possible Duplicate: java.lang.OutOfMemoryError: bitmap size exceeds VM budget - Android the following error occur when loading images to grid view. java.lang.OutOfMemoryError:
Solution 1:
try this
publicstatic Bitmap decodeFile(File f,int WIDTH,int HIGHT){
try {
//Decode image size
BitmapFactory.Optionso=newBitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(newFileInputStream(f),null,o);
//The new size we want to scale tofinalint REQUIRED_WIDTH=WIDTH;
finalint 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.Optionso2=newBitmapFactory.Options();
o2.inSampleSize=scale;
return BitmapFactory.decodeStream(newFileInputStream(f), null, o2);
}
catch (FileNotFoundException e) {}
returnnull;
}
this will scale bitmap as per width and height you pass..
Post a Comment for "Error In Loading Images To Gridview Android"