Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 856503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:14:43+00:00 2026-05-15T08:14:43+00:00

friends, i am using following code to display bitmap on screen and having next

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T08:14:44+00:00Added an answer on May 15, 2026 at 8:14 am

    You should decode with inSampleSize option to reduce memory consumption. Strange out of memory issue while loading an image to a Bitmap object

    Another option inJustDecodeBounds can help you to find correct inSampleSize value http://groups.google.com/group/android-developers/browse_thread/thread/bd858a63563a6d4a

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

friends, i am using following onDraw method to display bitmap on screen. @Override public
friends, i am using following code to display list with radio buttons now i
Using the following code to display a list of friends from my twitter profile.
friends, i am using following code to resizeImage private Bitmap resizeImage( final Bitmap image)
Friends, I'm populating a GridView in my asp.net application using following code. GridView grdExport
friends, i have created custom title bar using following titlebar.xml file with code <?xml
friends, i am trying to check internetconnectivity in android and using following code final
friends, i am using following code inside asyncTask public class AsycLoaderFromDbAndMapInjector extends AsyncTask {
friends, i am using following code to write Serializable object to external storage. it
I'm using the following code to retrieve the user's friends list and the info

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.