out of memory Exception while set it from file
If i am setting the scale more than 1 then image is stretching and
blurring or else it is giving out of memory exception. How to maintain
image original quality without out of memory exception. This is my code
public Bitmap decodeFile(File f){
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_SIZE=400;
//Find the correct scale value. It should be the power of 2.
int scale=1;
while(o.outWidth/scale/2>=REQUIRED_SIZE &&
o.outHeight/scale/2>=REQUIRED_SIZE)
scale*=2;
//scale*=2.5;
System.gc();
//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;
}
No comments:
Post a Comment