Here you can find the source of getFromUrl(String url)
Parameter | Description |
---|---|
url | the url |
Parameter | Description |
---|---|
IOException | Signals that an I/O exception has occurred. |
public static Bitmap getFromUrl(String url) throws IOException
//package com.java2s; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import android.graphics.Bitmap; import android.graphics.BitmapFactory; public class Main { /**/*from w w w . j a v a 2 s . c o m*/ * Gets the from url. * * @param url * the url * @return the from url * @throws IOException * Signals that an I/O exception has occurred. */ public static Bitmap getFromUrl(String url) throws IOException { URL myFileUrl = null; try { myFileUrl = new URL(url); } catch (MalformedURLException e) { e.printStackTrace(); } HttpURLConnection conn = (HttpURLConnection) myFileUrl .openConnection(); conn.setDoInput(true); conn.connect(); InputStream is = conn.getInputStream(); Bitmap bmImg = BitmapFactory.decodeStream(is); return bmImg; } }