1. 程式人生 > >一個uri有網路圖片,把這個圖片設定到imageview

一個uri有網路圖片,把這個圖片設定到imageview


myImageView.setImageURI(Uri.parse(http://example.com/logo.png)); 
try { 
    URL thumb_u = new URL("http://www.example.com/image.jpg"); 
    Drawable thumb_d = Drawable.createFromStream(thumb_u.openStream(), "src"); 
    myImageView.setImageDrawable(thumb_d); 

catch (Exception e) { 
    // handle it 

public Bitmap getRemoteImage(final URL aURL) { 
    try { 
        final URLConnection conn = aURL.openConnection(); 
        conn.connect(); 
        final BufferedInputStream bis = new BufferedInputStream(conn.getInputStream()); 
        final Bitmap bm = BitmapFactory.decodeStream(bis); 
        bis.close(); 
        return bm; 
    } catch (IOException e) {} 
    return null; 

setImageBitmap既可以了