`
Mr.Joe
  • 浏览: 133468 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Android ImageView显示网络图片

阅读更多
String url = "http://192.168.1.114:9000/data/attachments/342ac65c103853433bec12409113b07eca8088b4.jpg";
imgIV = (ImageView) findViewById(R.id.home_news_img_iv);
bitmap= Tools.getBitMap(url);
imgIV.setImageBitmap(bitmap);


package com.newsapp.util;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class Tools {
	
	public static Bitmap getBitMap(String url){
        URL myFileUrl = null;   
        Bitmap bitmap = null;  
        try {   
            myFileUrl = new URL(url);   
        } catch (MalformedURLException e) {   
            e.printStackTrace();   
        }   
        try {   
            HttpURLConnection conn = (HttpURLConnection) myFileUrl   
              .openConnection();   
            conn.setDoInput(true);   
            conn.connect();   
            InputStream is = conn.getInputStream();   
            bitmap = BitmapFactory.decodeStream(is);   
            is.close();   
        } catch (IOException e) {   
              e.printStackTrace();   
        }   
              return bitmap;   
    }  

}

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics