gpt4 book ai didi

android - 将 url 图像设置为 ImageView

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:26:38 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Is it possible to use BitmapFactory.decodeFile method to decode a image from http location?

我在将 url 图像设置为 ImageView 时遇到问题。我尝试了以下方法

方法一:

Bitmap bimage=  getBitmapFromURL(bannerpath);
image.setImageBitmap(bimage);

public static Bitmap getBitmapFromURL(String src) {
try {
Log.e("src",src);
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
Log.e("Bitmap","returned");
return myBitmap;
} catch (IOException e) {
e.printStackTrace();
Log.e("Exception",e.getMessage());
return null;
}
}

方法二:

    Drawable drawable = LoadImageFromWebOperations(bannerpath);
image.setImageDrawable(drawable);

private Drawable LoadImageFromWebOperations(String url)
{
try
{
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
}catch (Exception e) {
System.out.println("Exc="+e);
return null;
}
}

以上两种方法我都试过了,但都不行。两者都显示 DEBUG/skia(266): --- decoder->decode returned false 。我使用了有效的演示 url 图像路径。但是这条路行不通。所以请告诉我哪里出了问题,我会怎么做

提前谢谢你。

最好的问候。

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