Android Bitmap Load loadImage(String urlStr)

Here you can find the source of loadImage(String urlStr)

Description

load Image

Declaration

public static Bitmap loadImage(String urlStr) 

Method Source Code

//package com.java2s;
import java.io.IOException;
import java.io.InputStream;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class Main {
    public static Bitmap loadImage(String urlStr) {
        Bitmap bm = null;/*from w ww .  ja va 2  s.  c  o m*/

        HttpClient httpclient = new DefaultHttpClient();
        HttpParams params = httpclient.getParams();
        HttpConnectionParams.setConnectionTimeout(params, 1000 * 5);
        HttpConnectionParams.setSoTimeout(params, 1000 * 5);
        HttpGet httpGet = new HttpGet(urlStr);
        try {
            HttpResponse httpResponse = httpclient.execute(httpGet);
            HttpEntity entity = httpResponse.getEntity();
            InputStream is = entity.getContent();
            bm = BitmapFactory.decodeStream(is);
            is.close();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return bm;
    }
}

Related

  1. loadBitmap(String url)
  2. loadBitmapAsset(Context context, String asset)
  3. loadBitmapFromAssets(Context context, String name)
  4. loadBitmapFromStorage(String path)
  5. loadImage(String filename)
  6. loadPreviewBitmap(String fileName, int width, int height)
  7. SafeDecodeBitmapFile( String strFilePath)
  8. decodeF(File f)
  9. decodeFile(File f, int size)