1. 程式人生 > >獲取網路圖片的幾種方式

獲取網路圖片的幾種方式

   new Thread(new Runnable() {

@Override
public void run() {

try {
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection)
url.openConnection();
conn.setRequestMethod("GET");
conn.setReadTimeout(2000);
conn.connect();
if (conn.getResponseCode() == 200) {
InputStream is = conn.getInputStream();
//解析資料流 解析成圖片
Bitmap bitmap = BitmapFactory.decodeStream(is);
Message message = myHandler.obtainMessage();
message.obj = bitmap;
myHandler.sendMessage(message);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();