Android Bitmap Load loadBitmap(Activity activity, int resId, ImageView imageView, int reqWidth, int reqHeight)

Here you can find the source of loadBitmap(Activity activity, int resId, ImageView imageView, int reqWidth, int reqHeight)

Description

load Bitmap

Declaration

public static void loadBitmap(Activity activity, int resId,
            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 w  w  w  .  ja  va2 s  .c  o  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. getBitmapFromFileInputStream(FileInputStream is)
  2. getBitmapFromRes(Context context, int resId)
  3. getFromUrl(String url)
  4. getImageFromUri(Context ctx, Uri uri, int reqWidth, int reqHeight)
  5. getNetBitmap(String strUrl, File file, Context context, File file2)
  6. loadBitmap(Context c, String fileName)
  7. loadBitmap(Context c, String fileName, int width)
  8. loadBitmap(Context c, String fileName, int width, boolean sample)
  9. loadBitmap(InputStream is)