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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:43:22+00:00 2026-06-17T03:43:22+00:00

I am using the code of http://android-developers.blogspot.gr/2010/07/multithreading-for-performance.html in combination with http://developer.android.com/training/displaying-bitmaps/index.html code. when i

  • 0

I am using the code of http://android-developers.blogspot.gr/2010/07/multithreading-for-performance.html in combination with http://developer.android.com/training/displaying-bitmaps/index.html code. when i try to download the images from urls asynchronously without change the sample size everything it is ok. But when i try to calculate the sample size nothing appears on the screen(gridview). I read the logcat and i see that all the images are downloaded correctly. the code that i am using for the image download is the next one:

Bitmap downloadBitmap(String url) {

    final HttpClient client = AndroidHttpClient.newInstance("Android");
    final HttpGet getRequest = new HttpGet(url);

    try {
        HttpResponse response = client.execute(getRequest);
        final int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            Log.w("ImageDownloader", "Error " + statusCode
                    + " while retrieving bitmap from " + url);
            return null;
        }

        final HttpEntity entity = response.getEntity();
        if (entity != null) {
            InputStream inputStream = null;
            try {
                inputStream = entity.getContent();

                // get Device Screen Dimensions
                DeviceProperties dimensions = new DeviceProperties(activity);

                return 
                decodeBitmapFromResource(url, inputStream,
                        dimensions.getDeviceWidth(),
                        dimensions.getDeviceHeight());
            } finally {
                if (inputStream != null) {
                    inputStream.close();
                }
                entity.consumeContent();
            }
        }
    } catch (IOException e) {
        getRequest.abort();
        Log.w(TAG, "I/O error while retrieving bitmap from " + url, e);
    } catch (IllegalStateException e) {
        getRequest.abort();
        Log.w(TAG, "Incorrect URL: " + url);
    } catch (Exception e) {
        getRequest.abort();
        Log.w(TAG, "Error while retrieving bitmap from " + url, e);
    } finally {
        if ((client instanceof AndroidHttpClient)) {
            ((AndroidHttpClient) client).close();
        }
    }
    return null;
}

and the code i am using for decoding is this:

public static Bitmap decodeBitmapFromResource(String url, InputStream is,
        int reqWidth, int reqHeight) {
    // First decode with inJustDecodeBounds=true to check dimensions
    final BitmapFactory.Options options = new BitmapFactory.Options();

    options.inJustDecodeBounds = true;
    BitmapFactory.decodeStream(new FlushedInputStream(is), null,
            options);
    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options , reqWidth,
            reqHeight);

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeStream(new FlushedInputStream(is), null,
            options);
}

the problem appears when i use the both the first and the second BitmapFactory.decodeStream. If i use only the second one everything it is ok but actually i don’t make any sample. Any suggestion? I have lost a lot of time looking for it.

  • 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-17T03:43:24+00:00Added an answer on June 17, 2026 at 3:43 am

    A InputStream can only be read ONCE, then it is gone.

    If you want to make a dual pass (one for just the bounds and the second to have the options, you must first copy the input stream to a temporary file (using a FileOutputStream) and then do the dual pass on that file by opening two FileInputStream.

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

Sidebar

Related Questions

Re this example from the Android developer blog http://android-developers.blogspot.com/2011/04/customizing-action-bar.html It says that to style
I am Using APK Expansion File from http://developer.android.com/guide/market/expansion-files.html CODE : String[] path= getAPKExpansionFiles(this,2,0); ZipResourceFile
I'm following the barcode tutorial for this site: http://brismith66.blogspot.com/2010_07_01_archive.html using the google code: http://code.google.com/p/wsdl2objc/
I'm using http://developer.android.com/resources/tutorials/views/hello-mapview.html#top tutorial to show multi location in the map using markers.but it
I am using an ExpandableListView, same way they do in this sample code: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ExpandableList1.html
Looking at the example code in the docs http://developer.android.com/reference/android/content/Context.html#getExternalFilesDir%28java.lang.String%29 File path = getExternalFilesDir(Environment.DIRECTORY_PICTURES); It
Quick note: I'm using the SoundPool class http://developer.android.com/reference/android/media/SoundPool.html What I have here is a
I've been using MassTransit for handling e-mail messages. Using this code: http://meandaspnet.blogspot.com/2009/10/how-to-binary-serialize-mailmessage-for.html I'm able
I'm using http://code.google.com/p/flex-iframe/ for showing html in an flex application. To set this up
I create the custom title using the style.I code some from http://labs.makemachine.net/2010/03/custom-android-window-title/ I 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.