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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:02:24+00:00 2026-06-03T01:02:24+00:00

Hi all, I have searched a lot for my problem, I found a lot

  • 0

Hi all,
I have searched a lot for my problem, I found a lot of posts with similar problems, but no one gave me a correct solution.
What I want is a gridview displaying a sdcard folder’s images. I also have to offer the possibility to take a picture, and when going back to the gridview, update it with the new picture.

To take the picture, I use this code :

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, getImageFileUri());
startActivityForResult(intent, TAKE_PICTURE_ACTIVITY);

Where getImageFileUri() is a function giving me a picture name with a timestamp, using Environment.getExternalStorageDirectory() to get the sdcard path, and checking if the folder exists (and create it if it doesn’t).

For the moment, I use a cursor to get my images :

private void displayGallery() {

    // Query params :
    Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
    String[] projection = {MediaStore.Images.Media._ID};
    String selection = MediaStore.Images.Media.DATA + " like ? ";
    String[] selectionArgs = {"%Otiama%"};

    // Submit the query :
    mCursor = managedQuery(uri, projection, selection, selectionArgs, null);

    if (mCursor != null) {

        mGridView.setOnItemClickListener(this);
        mGridView.setAdapter(new ImageAdapter(this, mCursor));
    }

    else showToast("Gallery is empty : " + uri.toString());
}

And here is my adapter’s getView :

public View getView(int position, View convertView, ViewGroup parent) {

    ImageView imageView = new ImageView(mContext);

    // Move cursor to current position
    mCursor.moveToPosition(position);

    // Get the current value for the requested column
    int columnIndex = mCursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
    int imageID = mCursor.getInt(columnIndex);

    // obtain the image URI
    Uri uri = Uri.withAppendedPath( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Integer.toString(imageID) );
    String url = uri.toString();

    // Set the content of the image based on the image URI
    int originalImageId = Integer.parseInt(url.substring(url.lastIndexOf("/") + 1, url.length()));
    Bitmap b = MediaStore.Images.Thumbnails.getThumbnail(mContext.getContentResolver(), originalImageId, MediaStore.Images.Thumbnails.MINI_KIND, null);
    imageView.setImageBitmap(b);

    return imageView;
}

This code works, but is very slow and doesn’t update (new pictures’s thumbnails aren’t created), even if I call again my displayGallery() function in the onActivityResult(). Well, it doesn’t update even if I reload the app >< . I have to run it again from eclipse.

In fact, what I would like is the same behavior than ES File Explorer (when you open a folder, the pictures have all a preview image, and they are loaded asynchronously), which, I think, doesn’t use those ** thumbnails.

So I tried to load the pictures as bitmaps using the bitmap factory, but even with a few pictures (1-2), I instantly get a “java.lang.OutOfMemoryError: bitmap size exceeds VM budget”… I guess I have to resize them, but if I do so, won’t I have the same error when I will load 20-30 pictures ?? Or the problem is that each picture exceeds the budget, and so if I resize them I will avoid this error for all of them ?

Sorry for the big post, if someone can help…

  • 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-06-03T01:02:25+00:00Added an answer on June 3, 2026 at 1:02 am

    Well, I answer myself :
    I created my own thumbnails this way :

    public static Bitmap resizedBitmap(Bitmap bitmap, int newWidth) {
    
        // Get the bitmap size :
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        double ratio = (double)width / (double)height;
    
        // Compute the thumbnail size :
        int thumbnailHeight = newWidth;
        int thumbnailWidth = (int) ( (double)thumbnailHeight * ratio);
    
        // Create a scaled bitmap :
        Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, thumbnailWidth, thumbnailHeight, false);
    
        return scaledBitmap;
    }
    

    I don’t use cursors anymore, to load the thumbnails I proceed like this (in the ImageAdapter) :

    public void loadThumbnails() {
    
        // Init the ArrayList :
        _thumbnails = new ArrayList<ImageView>();
        _imagesNames = new ArrayList<String>();
    
        // Run through the thumbnails dir :
        File imagesThumbnailsDir = new File(_imagesThumbnailsDirUri.getPath());
        File[] imagesThumbnails = imagesThumbnailsDir.listFiles();
        Arrays.sort(imagesThumbnails);
    
        // For each thumbnail :
        for(File imageThumbnail : imagesThumbnails)
        {
            // Check if the image exists :
            File image = new File(_imagesDirUri.getPath() + File.separator + imageThumbnail.getName());
            if(image.exists()) {
    
                ImageView imageView = new ImageView(_context);
                imageView.setImageDrawable(Drawable.createFromPath(imageThumbnail.getAbsolutePath()));
    
                _thumbnails.add(imageView);
                _imagesNames.add(imageThumbnail.getName());
            }
    
            // If not, delete the thumbnail :
            else {
    
                ImageUtils.deleteFile(Uri.fromFile(imageThumbnail));
            }
        }
    }
    

    And so my ImageAdapter’s getView function sounds like this :

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    
        ImageView imageView;
        if (convertView == null) {
    
            imageView = new ImageView(_context);
            imageView.setLayoutParams(new GridView.LayoutParams(80, 80));
            imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
            imageView.setPadding(5, 5, 5, 5);
    
        } else {
            imageView = (ImageView) convertView;
        }
    
        imageView.setImageDrawable(_thumbnails.get(position).getDrawable());
    
        return imageView;
    }
    

    Hope it helps..

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

Sidebar

Related Questions

I have searched all around to find a solution to my problem, but i
I have searched a lot regarding my problem but no solution so i am
I have searched online but all the answers I have found were very primitive.
firstly i have searched a lot and all topics seems to be C# :
First of all I have searched many times in this forum but none is
I have searched all morning and yesterday afternoon and still cannot find an solution
First of all i want to say that i have searched each and every
OK I have looked and searched all i want to do is fire a
I have read the documentation and searched all over but I can't find how
I have searched in a lot of places and didn't find any solution for

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.