2012-01-20 2 views
0

인터넷에서 가져온 이미지보기로 이미지를 표시하고 있습니다. 문제는 해당 페이지를 볼 경우 항상 표시되지 않는 것입니다. 5 번만 3 또는 4 번 이미지가 표시됩니다. (매번 인터넷에서 이미지를 다운로드 할 때마다) 어떻게하면 매번 표시 할 수 있습니까?인터넷에서 이미지로드가 제대로 표시되지 않습니까?

public Bitmap getDrawable(String url) throws MalformedURLException, IOException { 
     Bitmap x; 

     HttpURLConnection connection = (HttpURLConnection)new URL(url) .openConnection(); 

     connection.connect(); 
     InputStream input = connection.getInputStream(); 

     x = BitmapFactory.decodeStream(input); 
     return x; 
    } 

for (int i = 0; i < imageSourceArray.length - 1; i++) { 
     detailedArticleImageViewArray[i] = new ImageView(
      ArticleActivity.this); 
     System.out.println(TMI + imageSourceArray[i + 1]); 
     Bitmap image = getDrawable(TMI + imageSourceArray[i + 1]); 
     detailedArticleImageViewArray[i].setImageBitmap(image); 
     detailedArticleImageViewArray[i].setLayoutParams(new LayoutParams(
      LayoutParams.MATCH_PARENT, 250)); 
     detailedArticleImageViewArray[0].setPadding(5, 10, 10, 5); 
       } 

나는 ... 닫혀 IOException이 버퍼의 InputStream을 얻고있다

또 다른 이유이다 디코드 반환 null 또는 거짓 ... 사전에

감사합니다 ..

답변

0

표시하려는 경우 이미지를 URL에서 가져온 다음 이것을 사용하십시오.

Bitmap mbmp = BitmapFactory.decodeStream(new java.net.URL("urlname").openStream()); 
Imageview_ref.setImageBitmap(mbmp); 

이미지를 표시 할 때마다 다운로드 할 필요가 없습니다. 여기에 내가 무엇입니까 문제가 아니다

+0

는 "IOException이 BufferedInput 스트림이 닫혀"오류 나는 새가 이미지를 보여줍니다 페이지 ... –

+0

비트 맵 mbmp = BitmapFactory.decodeStream를 (다시 열 때 java.net.URL ("urlname"). openStream()); 이 줄에 IOExcetion이 나타납니다. –

+0

이미지 URL이 ok가 아닌 null을 인쇄 했습니까? –

0

사용이 클래스

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; 
    } 
} 
관련 문제