gpt4 book ai didi

android - 如何从android中的url获取位图?

转载 作者:IT王子 更新时间:2023-10-29 00:02:47 27 4
gpt4 key购买 nike

我有一个类似图片的 uri

file:///mnt/...............

如何使用此 uri 获取图像但返回 null,请告诉我我哪里错了。

Bitmap bitmap = BitmapFactory.decodeFile(uri.getPath());
Bitmap bitmap = BitmapFactory.decodeFile(uri.toString());

最佳答案

这是一种简单的单行方式:

    try {
URL url = new URL("http://....");
Bitmap image = BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch(IOException e) {
System.out.println(e);
}

关于android - 如何从android中的url获取位图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11831188/

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