gpt4 book ai didi

java - 如何从远程源 (url) 获取图像并将其显示在 ImageView 中?

转载 作者:行者123 更新时间:2023-12-01 19:40:16 24 4
gpt4 key购买 nike

我正在构建一个 Android Things“信息亭”风格的应用程序,我希望图像像壁纸一样显示在背景中。我正在使用 Unsplash Source 来获取随机图像,但源 URL ( https://source.unsplash.com/1080x1920/?long-exposure ) 始终重定向到图像 URL,因此我无法使用此:

InputStream is = (InputStream) new URL("https://source.unsplash.com/1080x1920/?long-exposure").getContent();
Drawable d = Drawable.createFromStream(is, "");
niceWallpaper.setImageDrawable(d);

有办法做到这一点吗?

最佳答案

使用Picasso可以解决您的问题。

String yourUrl = "https://source.unsplash.com/1080x1920/?long-exposure";
Picasso.with(MyApplication.getAppContext()).load(yourUrl).placeholder(defaultImage).memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE).into(YourImageView);

关于java - 如何从远程源 (url) 获取图像并将其显示在 ImageView 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55583075/

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