gpt4 book ai didi

android - 使用 URL 设置 ImageView

转载 作者:行者123 更新时间:2023-11-30 03:37:39 25 4
gpt4 key购买 nike

我的服务器上有一个图像。图片的 URL 类似于: http://www.mydomain.com/123456uploaded_image.jpg

我正在尝试将此图像设置到我的 ImageView。这是我试过的代码:

    try{
String url1 = myeventimagearray[position];
URL ulrn = new URL(url1);
HttpURLConnection con = (HttpURLConnection)ulrn.openConnection();
InputStream is = (InputStream) con.getInputStream();
Bitmap bmp = BitmapFactory.decodeStream(is);
if (null != bmp)
iveventimg.setImageBitmap(bmp);
else
Log.i("Image","Not set");

} catch(Exception e) {
e.printStackTrace();
}

当我尝试这个时,我的 ImageView 是空的,也就是说,它没有设置 ImageView ,我在我的 logcat 中得到这个系统错误:

java.lang.ClassCastException: libcore.net.http.FixedLengthInputStream cannot be cast to com.example.eventnotifier.Base64$InputStream

Base46.java 是我从互联网上找到的一个文件,它对 Base64 符号进行编码和解码。

知道为什么我会收到此 System.error 吗?

谢谢

最佳答案

使用 URlImageViewHelper,它将负责将 url 加载到 ImageView 中。

Refer this

它将自己处理缓存、后台加载等。

关于android - 使用 URL 设置 ImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16389045/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com