2010-12-15 47 views

回答

11

使用此

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

InputStream is = connection.getInputStream(); 
Bitmap img = BitmapFactory.decodeStream(is); 

imageView.setImageBitmap(img); 
5

下面的代码应该帮助你阅读图像。但请记住,如果您在UI线程中执行此操作,则会挂起UI。您应该始终打开一个新线程并在该线程中加载图像。所以你的应用总是保持响应。

InputStream is = null; 
BufferedInputStream bis = null; 
Bitmap bmp = null; 
try { 
    URLConnection conn = url.openConnection(); 
    conn.connect(); 
    is = conn.getInputStream(); 
    bis = new BufferedInputStream(is); 
    bmp = BitmapFactory.decodeStream(bis); 
} catch (MalformedURLException e) { 

} catch (IOException e) { 

} finally { 
    try { 
     is.close(); 
     bis.close(); 
    } catch (IOException e) { 

    } 
} 
imageView.setImageBitmap(bmp); 
0

它在this link

请参阅本已讨论,这将是富有成果..

拥有一个美满的编码... !!!