Here you can find the source of loadBitmap(String bitmapUrl, ImageView imageView, int reqWidth, int reqHeight)
public static void loadBitmap(String bitmapUrl, ImageView imageView, int reqWidth, int reqHeight)
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); } }