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

  • Home
  • SEARCH
  • 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 8160185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:09:34+00:00 2026-06-06T18:09:34+00:00

How to get thumbnails from sdcard with the given URI ?? I have tried

  • 0

How to get thumbnails from sdcard with the given URI ??
I have tried using bitmapfactory but the performance is bad or OutOfMemoryError
I am going to put the thumbnails to the listview with a lot of data
should I use thumbnails or any suggestions?
if thumbnails are to be used then how to do it…?

Thanks in advance for the 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-06T18:09:35+00:00Added an answer on June 6, 2026 at 6:09 pm

    The following method can be used to get the thumbnail of image:

    private Bitmap getBitmap(String path) {
    
        Uri uri = getImageUri(path);
        InputStream in = null;
        try {
            final int IMAGE_MAX_SIZE = 1200000; // 1.2MP
            in = mContentResolver.openInputStream(uri);
    
            // Decode image size
            BitmapFactory.Options o = new BitmapFactory.Options();
            o.inJustDecodeBounds = true;
            BitmapFactory.decodeStream(in, null, o);
            in.close();
    
    
    
            int scale = 1;
            while ((o.outWidth * o.outHeight) * (1 / Math.pow(scale, 2)) > IMAGE_MAX_SIZE) {
                scale++;
            }
            Log.d(TAG, "scale = " + scale + ", orig-width: " + o.outWidth       + ", orig-height: " + o.outHeight);
    
            Bitmap b = null;
            in = mContentResolver.openInputStream(uri);
            if (scale > 1) {
                scale--;
                // scale to max possible inSampleSize that still yields an image
                // larger than target
                o = new BitmapFactory.Options();
                o.inSampleSize = scale;
                b = BitmapFactory.decodeStream(in, null, o);
    
                // resize to desired dimensions
                int height = b.getHeight();
                int width = b.getWidth();
                Log.d(TAG, "1th scale operation dimenions - width: " + width    + ", height: " + height);
    
                double y = Math.sqrt(IMAGE_MAX_SIZE
                        / (((double) width) / height));
                double x = (y / height) * width;
    
                Bitmap scaledBitmap = Bitmap.createScaledBitmap(b, (int) x,     (int) y, true);
                b.recycle();
                b = scaledBitmap;
    
                System.gc();
            } else {
                b = BitmapFactory.decodeStream(in);
            }
            in.close();
    
            Log.d(TAG, "bitmap size - width: " +b.getWidth() + ", height: " + b.getHeight());
            return b;
        } catch (IOException e) {
            Log.e(TAG, e.getMessage(),e);
            return null;
        }
    }
    

    And always call bitmap.recycle() method after using bitmaps. It will clear the bitmap from memory. Also avoid memory leaks in your code. This will solve your OOME.

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

Sidebar

Related Questions

I'm trying to get video thumbnails from Vimeo, but for some reason, I cannot
I'm creating thumbnails from videos using ffmpeg and it's working fine. But now I
I have an image uploader and cropper which creates thumbnails and I occasionally get
I'm using sorl-thumbnail to get some images to crop. I have a model looking
I'm trying to get the thumbnails from Youtube and insert the corresponding image into
I am trying to get a view with multiple pictures as thumbnails; but i
I have a site, where I load a list of images (thumbnails) from the
I have problem to change the border color of the visited thumbnails using Galleriffic.
I want to create gallery application which would get thumbnails and metadata from web
I need to generate thumbnails from a set of jpg's that need to have

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.