带有来自 URL 的图像的 Imageview

发布于 2024-12-21 02:04:49 字数 99 浏览 5 评论 0原文

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

谢谢!

i'm searching for a modified Imageviewclass which downloads a image and displays it.
It should also be possible to display a "download fail"-image and a "load"-image.
If anyone knows a class like this please let me know it.

Thx!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

少跟Wǒ拽 2024-12-28 02:04:49

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

网页图像视图

You can use this example, just pass the Activity instance in a constructor and extend the view class instead of the Activity class.

Web Imageview

纵山崖 2024-12-28 02:04:49

希望这对你有帮助:

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);
} 

Hope this helps u:

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);
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文