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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:28:53+00:00 2026-06-09T03:28:53+00:00

I am trying to resize a picture selected from the SD card to a

  • 0

I am trying to resize a picture selected from the SD card to a thumbnail size but when I resize it, to the dimensions on my default image 128/128 the bitmap is null

InputStream input=null;
            try {
                input = getActivity().getContentResolver().openInputStream(Uri.parse(cursor.getString(3)));
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inJustDecodeBounds = true;
                BitmapFactory.decodeStream(input, null, options);
                int height = options.outHeight; //1030
                int width = options.outWidth; //1033
                BitmapFactory.decodeResource(getResources(), R.drawable.ic_contact_picture, options);

                int imageHeight = options.outHeight; //128
                int imageWidth = options.outWidth; //128


                if(imageWidth > imageHeight){
                    options.inSampleSize = Math.round((float)height/(float)imageHeight);
                }else{
                    options.inSampleSize = Math.round((float)width/(float)imageWidth);
                }
                options.inJustDecodeBounds = false;
                Bitmap bm = BitmapFactory.decodeStream(input,null, options); //null here
                try {
                    input.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                image.setImageBitmap(bm);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }

I can get both of the images height and width but when I go to resize it, it returns a null bitmap.

I have done it this way with resource files but never with a Uri of an image from the SD card so what am I doing wrong?

  • 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-09T03:28:54+00:00Added an answer on June 9, 2026 at 3:28 am

    You can’t use the same input stream twice, so you will need to create a new InputStream the second time. See here for more info.

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

Sidebar

Related Questions

I'm trying to resize an image loaded from disk - a JPG or PNG
I am trying to resize the image using javascript, but I am getting errors
Trying to resize (enlarge) an image with animate(). Didn't manage to resize it from
I trying to resize one image from InputStream, so I use the code in
I'm trying to resize my image after copying it from the screen, and can't
I am currently trying to resize a picture that I am downloading from the
I am trying to resize an image's size and then putting it in a
I am trying to use Python to resize picture. With my camera, files are
I'm trying to resize a fullsize image poster into three smaller variants of the
I'm trying to resize an image in Silverlight 3 that has been submitted by

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.