如何使用Android中使用URL的图像工作?如何使用、图像、工作、URL

2023-09-12 06:26:18 作者:站住,打劫棒棒糖!

给出一个网址的形象,我想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" />