如何从android中的特定网址读取图像?如何从Android中的特定网址读取图像
4
A
回答
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
参见[当前页...](http://stackoverflow.com/questions/2471935/how-to-load-an-imageview-by-url-in-android) 这将是有帮助.. 快乐编码... !!!! – Dhasneem 2013-04-24 13:34:50