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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:20:26+00:00 2026-06-06T13:20:26+00:00

Ok so i download a image and send the input stream to this method

  • 0

Ok so i download a image and send the input stream to this method witch has to decode it once to find the image size then calculate a scale value then create a mini version of the bitmap from the stream…. but i get errors in logcat that the bitmapFactory is returning null, anyone have a idea what could be wrong ?

public static Bitmap getSampleBitmapFromStream(InputStream is,
        int reqWidth, int reqHeight) {

    BitmapFactory.Options options = new BitmapFactory.Options();

    options.inJustDecodeBounds = true;
    BitmapFactory.decodeStream(new FlushedInputStream(is), null, options);


    // Find the correct scale value. It should be the power of 2.
    int width_tmp = options.outWidth, height_tmp = options.outHeight;
    int scale = 1;
    while (true) {
        if (width_tmp / 2 < reqWidth || height_tmp / 2 < reqHeight)
            break;
        width_tmp /= 2;
        height_tmp /= 2;
        scale *= 2;
    }

    // decode with inSampleSize
    options.inJustDecodeBounds = false;
            options.inSampleSize = scale;
    return BitmapFactory.decodeStream(new FlushedInputStream(is), null, options);

}
  • 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-06T13:20:28+00:00Added an answer on June 6, 2026 at 1:20 pm

    the reason is: the stream you used twice

    options.inJustDecodeBounds = true;
    BitmapFactory.decodeStream(new FlushedInputStream(is), null, options);
    

    and again:

     options.inJustDecodeBounds = false;
            options.inSampleSize = scale;
    return BitmapFactory.decodeStream(new FlushedInputStream(is), null, options);
    

    so if you want avoid this, you need close the stream and reopen the stream again.

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

Sidebar

Related Questions

I download an image from newsgroups with the nntplib module in python. I then
When I use this code to download this image (only used for testing purposes),
I want to force the download of an image. I have found this code:
I'm using AsyncTask to download an image and want to send the downloaded image
I just want to download an image. Then upload it to Amazon S3. But
I need to download an image from some URL to my server. However, my
I am trying to download the image from the url http://a3.twimg.com/profile_images/414797877/05052008321_bigger.jpg I am using
How can I use php to download an image from URL (eg: https://www.google.com/images/srpr/logo3w.png )
I am looking for a way to force the browser to download an image
I need to download an image from the internet, in a different thread, and

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.