下載網絡圖片顯示在Android手機上

ImageView imageView = (ImageView) findViewById(R.id.imageView);
Bitmap bitMap = null;
try
{
    URL uri = new URL("http://www.qiwen007.com/images/ext_jpg/201608/09_135735gb.jpg");
    HttpURLConnection conn = (HttpURLConnection) uri.openConnection();
    conn.setDoInput(true);
    conn.connect();
    InputStream inputStream = conn.getInputStream();
    bitMap = BitmapFactory.decodeStream(inputStream);
    inputStream.close();
} catch (Exception e)
{
    e.printStackTrace();
}
imageView.setImageBitmap(bitMap);android


<ImageView android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/imageView" />
        
        
<uses-permission android:name="android.permission.INTERNET" />code

相關文章
相關標籤/搜索