java.lang.OutOfMemoryError: bitmap size exceeds VM budget ?
Posted
by UMMA
on Stack Overflow
See other posts from Stack Overflow
or by UMMA
Published on 2010-06-15T07:10:00Z
Indexed on
2010/06/15
7:12 UTC
Read the original article
Hit count: 832
android
friends,
i am using following code to display bitmap on screen and having next and previous buttons to change images.
and getting out of memory error
New Code
HttpGet httpRequest = null;
try {
httpRequest = new HttpGet(mImage_URL[val]);
} catch (Exception e) {
return 0;
}
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
Bitmap bm;
HttpEntity entity = response.getEntity();
BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
InputStream is = bufHttpEntity.getContent();
try
{
bm = BitmapFactory.decodeStream(is);
}catch(Exception ex)
{
}
is.close();
Old Code
URL aURL = new URL(mImage_URL[val]);
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = null;
try
{
is= conn.getInputStream();
}catch(IOException e)
{
}
BufferedInputStream bis = new BufferedInputStream(is);
bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
img.setImageBitmap(bm);
and it was giving me error decoder->decode return false.
on images of size bigger than 400kb.
so after googling i got new code as answer the old code was not giving me out of memory error on those images but decoder->decode return false, so i choosed new code.
any one guide me what is the solution and which is the best approach to display live images?
© Stack Overflow or respective owner