2010-12-15 19 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

請參閱本已討論,這將是富有成果..

擁有一個美滿的編碼... !!!

相關問題