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