Android Bitmap Load getFromUrl(String url)

Here you can find the source of getFromUrl(String url)

Description

Gets the from url.

Parameter

Parameter Description
url the url

Exception

Parameter Description
IOException Signals that an I/O exception has occurred.

Return

the from url

Declaration

public static Bitmap getFromUrl(String url) throws IOException 

Method Source Code

//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;
    }
}

Related

  1. getBitmapFromAsset(Context context, String strName)
  2. getBitmapFromFile(File file)
  3. getBitmapFromFile(String filePath)
  4. getBitmapFromFileInputStream(FileInputStream is)
  5. getBitmapFromRes(Context context, int resId)
  6. getImageFromUri(Context ctx, Uri uri, int reqWidth, int reqHeight)
  7. getNetBitmap(String strUrl, File file, Context context, File file2)
  8. loadBitmap(Activity activity, int resId, ImageView imageView, int reqWidth, int reqHeight)
  9. loadBitmap(Context c, String fileName)