来自Url的Imageview图像

时间:2011-12-12 17:55:20

标签: android android-imageview android-image

我正在搜索修改后的Imageviewclass,它会下载图像并显示它。 还应该可以显示“下载失败” - 图像和“加载”图像。 如果有人知道这样的课程,请告诉我。

THX!

2 个答案:

答案 0 :(得分:1)

您可以使用此示例,只需在构造函数中传递Activity实例并扩展视图类而不是Activity类。

Web Imageview

答案 1 :(得分:1)

希望这有助于你:

ImageView i = new ImageView(this);
i.setImageResource(" ur load image" ) // show any load image here..eg. gallery image
try {
/* Open a new URL and get the InputStream to load data from it. */
URL aURL = new URL("ur Image URL");
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
/* Buffered is always good for a performance plus. */
BufferedInputStream bis = new BufferedInputStream(is);
/* Decode url-data to a bitmap. */
Bitmap bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
/* Apply the Bitmap to the ImageView that will be returned. */
i.setImageBitmap(bm);
} catch (IOException e) {
 i.setImageResource(R.drawable.error); // Error image here
Log.e("DEBUGTAG", "Remote Image Exception", e);
}