如何使用Android中使用URL的图像工作? [英] How to work with an image using url in android?

查看:110
本文介绍了如何使用Android中使用URL的图像工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出一个网址的形象,我想downoload并粘贴到我的android系统中的画布。如何重新获取图像到我的应用程序?

Given a Url for an image, I want to downoload it and paste it onto my canvas in android. How do I retrieve the image into my app ?

请帮忙。

谢谢, 德costo。

Thanks, de costo.

推荐答案

您可以使用下面的code下载图像:

You can use the following code to download an image:

URLConnection connection = uri.toURL().openConnection();
connection.connect();
InputStream is = connection.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is, 8 * 1024);
Bitmap bmp = BitmapFactory.decodeStream(bis);
bis.close();
is.close(); 

需要以下权限在AndroidManifest.xml中:

Requires the following permission in AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET" />

这篇关于如何使用Android中使用URL的图像工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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