如何从Android的一个url得到位图? [英] How to get bitmap from a url in android?

查看:84
本文介绍了如何从Android的一个url得到位图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

解决方案

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

 网​​址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());

这篇关于如何从Android的一个url得到位图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆