Android Bitmap Load loadBitmap(String bitmapUrl, ImageView imageView, int reqWidth, int reqHeight)

Here you can find the source of loadBitmap(String bitmapUrl, ImageView imageView, int reqWidth, int reqHeight)

Description

load Bitmap

Declaration

public static void loadBitmap(String bitmapUrl, ImageView imageView,
            int reqWidth, int reqHeight) 

Method Source Code

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.support.v4.util.LruCache;
import android.util.Log;
import android.widget.ImageView;

public class Main{
    private static LruCache<String, Bitmap> mMemoryCache;
    public static void loadBitmap(String bitmapUrl, ImageView imageView,
            int reqWidth, int reqHeight) {
        if (imageView != null && bitmapUrl != null) {
            //check cache
            Bitmap bitmap = getBitmapFromMemCache(bitmapUrl.toString());
            if (bitmap != null) {
                imageView.setImageBitmap(bitmap);
                return;
            }/*from  ww w .j a va2 s.co  m*/
            BitmapFromUrlTask task = new BitmapFromUrlTask(imageView,
                    reqWidth, reqHeight);
            task.execute(bitmapUrl);
        }
    }
    public static void loadBitmap(Activity activity, int resId,
            ImageView imageView, int reqWidth, int reqHeight) {
        BitmapFromResourcesTask task = new BitmapFromResourcesTask(
                activity, imageView, reqWidth, reqHeight);
        task.execute(resId);
    }
    private static Bitmap getBitmapFromMemCache(String key) {
        return mMemoryCache.get(key);
    }
}

Related

  1. loadBitmap(Activity activity, int resId, ImageView imageView, int reqWidth, int reqHeight)
  2. loadBitmap(Context c, String fileName)
  3. loadBitmap(Context c, String fileName, int width)
  4. loadBitmap(Context c, String fileName, int width, boolean sample)
  5. loadBitmap(InputStream is)
  6. loadBitmap(String url)
  7. loadBitmap(String url)
  8. loadBitmap(String url)
  9. loadBitmapAsset(Context context, String asset)