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 6576403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:30:29+00:00 2026-05-25T15:30:29+00:00

I’m trying to learn how to display all the images stored on an android

  • 0

I’m trying to learn how to display all the images stored on an android phone in a grid view (my goal is to have a user select which image they want to process).

I am adapting the tutorial at:

http://developer.android.com/resources/tutorials/views/hello-gridview.html

to do so.

http://pastie.org/2504664

Above is a link to my modified ImageAdapter class (the only thing I believe needs to be changed).

In it, rather than having an integer array of Resources ids, I have a string array of media file locations, and turn them into a bitmap like so:

imageView.setImageBitmap(BitmapFactory.decodeFile(picture_paths[position]));

I’m getting the file locations in the first place by:

   public void populateArray(){
      Log.v("Jenny","Populating array");
      picture_paths = new String[getCount()];
      cursor.moveToFirst();
      int count = 0;
      while(!cursor.isLast() ){
          count ++;
          picture_paths[cursor.getPosition()] = cursor.getString(0);
          cursor.moveToNext();
      }

}

It works like a gem, as long as I have less than 9 pictures (in three columns of three).

Any more than that, and the thing crashes with an “Out of Memory” error. If I just follow the tutorial and use resource images, I can have as many as I like, it seems.

So: Am I going about this the wrong way? Is loading it as a Bitmap to intensive? What alternatives are there?

Displaying the images stored on the phone seems like a really trivial, basic task. What is the “right” way to do this, and is there anyway I can make this way work?

Edit: Testing on my second phone (a Galaxy) makes things work just fine (can display any number of images, though it seems like sometimes the file path retrieved by the cursor are ‘null’). On my original testing phone (a myTouch) I get the memory error no matter how I attempt to display the images (drawable, bitmaps, whatever). Why would I get different behaviors on the two phones?

Edit: Well, one thing that might be going on is that my myTouch has more pictures on it? I took a few more pics with my Galaxy and now it is getting out of memory errors as well…. Is grid view not for displaying photos (if not, what good is it?)

Still limited to 9 on myTouch but can go to 11 on Galaxy

Both crash with an out of Memory error when rotated (i.e the view redraws). (though not with a small amount of pics (less than 6 maybe?)

  • 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-25T15:30:29+00:00Added an answer on May 25, 2026 at 3:30 pm

    Try resizing your images to maybe half their size.

    BitmapFactory.Options o = new BitmapFactory.Options();
    o.inSampleSize = 5;
    Bitmap previewBitmap = Bitmap.createScaledBitmap(
                    BitmapFactory.decodeFile(picLocation, o), 
                    85, 
                    85, 
                    false);
    imageView.setImageBitmap(previewBitmap);
    

    This should reduce the number of size of the image by 1/5 and 1/25 the number of pixels according to the documentation. Raise or lower o.inSampleSize to other values depending on what you want. Also, in the createScaledBitmap you can change the size of the bitmap by changing the 85 to whatever dimensions you want.

    Other resources that may help if this doesn’t:

    android – out of memory exception when creating bitmap

    Strange out of memory issue while loading an image to a Bitmap object

    Out of memory exception due to large bitmap size

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to select an H1 element which is the second-child in its group
I have a text area in my form which accepts all possible characters from
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have a view passing on information from a database: def serve_article(request, id): served_article
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
Basically, what I'm trying to create is a page of div tags, each has

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.