2011-06-27 9 views
1

下のURLから画像を読み込むにはどうしたらいいですか? http://images.google.com/hosted/life/l?imgurl=46d75bbfa52a8450Androidからの表示画像

Googleカスタム検索APIを使用して、images.google.comの画像を検索しています。 リンクタグの内容を含むjsonファイルを返します。例:http://images.google.com/hosted/life/l?imgurl=46d75bbfa52a8450。私はそれを私の見解にロードしたい。

URLがendwithファイルの場合、 ".jpgまたは.png"を拡張すると、ダウンロードして表示できます。 しかし、そうでなければ、私はイメージを得ることができます。 誰でも私を助けることができます。

+0

画像をImageViewに読み込もうとしていますか? JSONレスポンスの内容を投稿できますか? – sparkymat

答えて

1

こんにちは、以下のコードを使用してください。

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; 
    } 
    } 
+0

このコードをくれてありがとう。しかし、私はそれを実行します。エラーをスローします。SkImageDecoder :: Factoryはnullを返します。 – kikura

関連する問題