如何从Android的一个url得到位图?位图、Android、url

2023-09-12 07:43:41 作者:把妳的交給我

我有一个URI像其中有一个形象

 文件:/// MNT / ...............
 

如何使用URI来获取图像,但它返回null,请告诉我,我错了。

 位图位= BitmapFactory.de codeFILE(uri.getPath());
点阵位图= BitmapFactory.de codeFILE(uri.toString());
 

解决方案 Android studio怎么得到一个最近访问文件列表

这是一个简单的一条线的方式来做到这一点:

 网​​址URL =新的URL(HTTP:// ......);
位图图像= BitmapFactory.de codeStream(url.openConnection()的getInputStream());
 

I have a uri like which has an image

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

How to use this uri to get the image but it returns null, please tell me where i am wrong.

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

解决方案

This is a simple one line way to do it:

URL url = new URL("http://....");
Bitmap image = BitmapFactory.decodeStream(url.openConnection().getInputStream());