- Code: Select all
public void setBackgroundImage(Uri uri) throws FileNotFoundException {
InputStream is = null ;
try {
Bitmap bm;
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inJustDecodeBounds = true;
BitmapFactory.decodeStream(is, null, opt);
opt.inSampleSize = 1;
Display d;
WindowManager wm = (WindowManager) getContext().getSystemService(
Context.WINDOW_SERVICE);
d = wm.getDefaultDisplay();
h = d.getHeight();
w = d.getWidth();
while ((opt.outWidth/opt.inSampleSize) > w ||
(opt.outHeight/opt.inSampleSize) > h ) {
opt.inSampleSize <<= 1;
}
opt.inJustDecodeBounds = false;
is = getContext().getContentResolver().openInputStream(
uri);
bm = BitmapFactory.decodeStream(is, null, opt);
super.setImageBitmap(bm);
} catch (IOException e) {
if ( e instanceof FileNotFoundException){
throw (FileNotFoundException)e;
}else {
Log.e("CompositeImage", "Failed to decode"
+ e.toString());
}
}finally {
if (null != is) {
try {
is.close();
} catch (Exception e) {
//Can't do anything
}
}
}
}
Above code is working fine for all jpeg, Png, and bmp images.
But is giving OutofMemoryException for Gif images of Size 5MB or more.
Has anybody seen this problem. Is there any solution to it?
Thanks,
With Regards /


