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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:32:05+00:00 2026-05-18T08:32:05+00:00

I am writing a little picture frame app for android that is using opengl

  • 0

I am writing a little picture frame app for android that is using opengl for part of the UI. This portion needs to get images from flickr and load them into a texture. The code I have below is functional most of the time, but it has a Thread.sleep() kludge in between getting the input stream from the connection and the bitmap factory decoding the stream:

            URL url = new URL("http://farm5.static.flickr.com/4132/5168797476_7a85deb2be_b.jpg");
            URLConnection con = url.openConnection();
            InputStream is = con.getInputStream();
            Thread.sleep(250); //What am I actually waiting for?
            sourceBitmap = BitmapFactory.decodeStream(is);

How do I get around using the sleep() method in favor of something that makes logical sense?

I am testing on a samsung galaxy tab not in the emulator

  • 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-05-18T08:32:06+00:00Added an answer on May 18, 2026 at 8:32 am

    This seems less than ideal, but if you read the stream byte by byte into a buffer and then pass the byte array to the BitmapFactory it works correctly.

                URL url = new URL("http://farm5.static.flickr.com/4132/5168797476_7a85deb2be_b.jpg");
                URLConnection con = url.openConnection();
                con.connect();
                int fileLength = con.getContentLength();
                InputStream is = con.getInputStream();
                byte[] bytes = new byte[fileLength];
                for(int i=0;i<fileLength;i++) {
                    bytes[i] = (byte)is.read();
                }
                sourceBitmap = BitmapFactory.decodeByteArray(bytes, 0, fileLength);
    

    I tried reading the bytes into the buffer all at once with is.read(bytes, 0, fileLength) but it did not reliably fill the buffer completely unless I waited a moment before calling the read. Is it possible that android implementation of InputStream’s read method is flawed causing the BitmapFactory’s decodeStream method to fail due to incomplete data?

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

Sidebar

Related Questions

I'm writing a little desktop app that should be able to encrypt a data
I'm writing a little debug app for a bit of kit we're developing and
I've been writing a little application that will let people upload & download files
I am currently writing a little bootstrap code for a service that can be
I'm writing a little web-based utility for my brother who needs to merge columns
I'm writing a little utility that starts with selecting a file, and then I
I'm writing a simple control in C# that works like a picture box, except
I'm writing a little program where I select a picture through an open file
I'm currently writing a little GUI program that does some work and exits afterwards.
I am writing my first little Access 2003 application. I have two queries that

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.