2011-03-25 2 views
2

일부 URL에서 이미지를 가져 와서 ImageView에 표시하고 싶습니다. 다음은 내가 사용하고있는 코드입니다 : -setImageURI/setimagebitmap net에서 이미지를 가져 와서 이미지보기에 표시

Bitmap bm = null; 
    try { 
     URL aURL = new URL("stringURL"); 
     URLConnection conn = aURL.openConnection(); 
     conn.connect(); 
     InputStream is = conn.getInputStream(); 
     BufferedInputStream bis = new BufferedInputStream(is); 
     bm = BitmapFactory.decodeStream(bis); 
     bis.close(); 
     is.close(); 
    }catch (Exception e) { 
     // TODO: handle exception 
} 
    iv.setImageBitmap(bm); 

하지만 난 오류가

URL aURL = new URL("stringURL"); 

따옴표없이해야에 생각하는 이미지를

답변

0

를 얻을 수

URL aURL = new URL(stringURL); 

stringURL이 유효한 URL 인 경우 ...

도움이 되길 ../

0

아래 코드를 사용하면 더 잘 될 것입니다.

String stringURL = "Your url here"; 

InputStream is = null; 
BufferedInputStream bis = null; 
Bitmap bmp = null; 

try { 
    URL url = new URL(stringURL); 
    URLConnection conn = url.openConnection(); 
    conn.connect(); 
    is = conn.getInputStream(); 
    bis = new BufferedInputStream(is); 
    bmp = BitmapFactory.decodeStream(bis); 

} catch (MalformedURLException e) { 

} catch (IOException e) { 

}catch (Exception e) { 

} finally { 
    try { 
     if(is != null) 
      is.close(); 
     if(bis != null) 
      bis.close(); 
    } catch (IOException e) { 

    } 
} 
iv.setImageBitmap(bmp); 
관련 문제