1

How can I load image from below url . http://images.google.com/hosted/life/l?imgurl=46d75bbfa52a8450

I use Google Custom Search API to search image from site images.google.com . It will return a json file with contents of link tag . Example : http://images.google.com/hosted/life/l?imgurl=46d75bbfa52a8450 . And I want to load it to my view .

If URL is endwith file extends ".jpg or .png", i can download and display it . But if not , i can get the image . Anyone can help me .

1
  • Are you trying to load the image into an ImageView? Can you post the contents of the JSON response? Commented Jun 27, 2011 at 7:28

1 Answer 1

1

Hi Please used below code.

  String url = "http://images.google.com/hosted/life/l?imgurl=46d75bbfa52a8450";
    InputStream ins = null;
    try {
        ins = new java.net.URL(url).openStream();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    Bitmap b = BitmapFactory.decodeStream(new FlushedInputStream(ins));
    imageview.setImageBitmap(b);

 static class FlushedInputStream extends FilterInputStream {
    public FlushedInputStream(InputStream inputStream) {
        super(inputStream);
    }

    @Override
    public long skip(long n) throws IOException {
        long totalBytesSkipped = 0L;
        while (totalBytesSkipped < n) {
            long bytesSkipped = in.skip(n - totalBytesSkipped);
            if (bytesSkipped == 0L) {
                int b = read();
                if (b < 0) {
                    break; // we reached EOF
                } else {
                    bytesSkipped = 1; // we read one byte
                }
            }
            totalBytesSkipped += bytesSkipped;
        }
        return totalBytesSkipped;
    }
  }
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for give me this code . But when I run it . It throws an error SkImageDecoder::Factory returned null.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.