Android Utililty Methods Bitmap Load

List of utility methods to do Bitmap Load

Description

The list of methods to do Bitmap Load are organized into topic(s).

Method

voidloadBitmap(String bitmapUrl, ImageView imageView, int reqWidth, int reqHeight)
load Bitmap
if (imageView != null && bitmapUrl != null) {
    Bitmap bitmap = getBitmapFromMemCache(bitmapUrl.toString());
    if (bitmap != null) {
        imageView.setImageBitmap(bitmap);
        return;
    BitmapFromUrlTask task = new BitmapFromUrlTask(imageView,
            reqWidth, reqHeight);
...
BitmaploadBitmap(String url)
Load bitmap.
Bitmap bitmap = null;
InputStream in = null;
BufferedOutputStream out = null;
try {
    in = new BufferedInputStream(new URL(url).openStream(),
            IO_BUFFER_SIZE);
    final ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
    out = new BufferedOutputStream(dataStream, IO_BUFFER_SIZE);
...
BitmaploadBitmap(String url)
Loads a bitmap from the specified url.
Bitmap bitmap = null;
InputStream in = null;
BufferedOutputStream out = null;
try {
    in = new BufferedInputStream(new URL(url).openStream(),
            IO_BUFFER_SIZE);
    final ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
    out = new BufferedOutputStream(dataStream, IO_BUFFER_SIZE);
...
BitmaploadBitmap(String url)
Loads a bitmap from the specified url.
Bitmap bitmap = null;
InputStream in = null;
BufferedOutputStream out = null;
try {
    in = new BufferedInputStream(new URL(url).openStream(),
            IO_BUFFER_SIZE);
    final ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
    out = new BufferedOutputStream(dataStream, IO_BUFFER_SIZE);
...
BitmaploadBitmapAsset(Context context, String asset)
load Bitmap Asset
InputStream is = null;
Bitmap bitmap = null;
try {
    is = context.getAssets().open(asset);
    if (is != null) {
        bitmap = BitmapFactory.decodeStream(is);
} catch (IOException e) {
...
BitmaploadBitmapFromAssets(Context context, String name)
load Bitmap From Assets
try {
    InputStream is = context.getAssets().open(name);
    Bitmap bitmap = BitmapFactory.decodeStream(is);
    return bitmap;
} catch (IOException e) {
    e.printStackTrace();
return null;
...
BitmaploadBitmapFromStorage(String path)
load Bitmap From Storage
try {
    FileInputStream is = new FileInputStream(path);
    Bitmap bitmap = BitmapFactory.decodeStream(is);
    return bitmap;
} catch (FileNotFoundException e) {
    e.printStackTrace();
return null;
...
BitmaploadImage(String filename)
Load an image
File root = Environment.getExternalStorageDirectory();
try {
    File directory = new File(root.getPath() + ROOT_DIRECTORY);
    String filepath = directory.getPath() + "/" + filename;
    Options option = new Options();
    if (ApiLevels.getApiLevel() >= 4) {
        option = ApiLevel4.setInScaled(option, false);
    return BitmapFactory.decodeFile(filepath, option);
} catch (Exception e) {
    Log.e("ARTags:BitmapUtil:saveImage",
            "Exception while loading the tag", e);
return null;
BitmaploadImage(String urlStr)
load Image
Bitmap bm = null;
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);
...
BitmaploadPreviewBitmap(String fileName, int width, int height)
200px PreviewBitmap
try {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = false;
    options.inSampleSize = 1;
    File file = new File(fileName);
    if (!file.exists()) {
        return null;
    if (file.length() > 4 * 1024 * 1024) {
        options.inSampleSize = 4;
    } else if (file.length() > 1024 * 1024) {
        options.inSampleSize = 2;
    Bitmap bm = BitmapFactory.decodeFile(fileName, options);
    if (bm != null) {
        Bitmap resizebm = resizePreviewBitmap(bm, width, height);
        bm.recycle();
        return resizebm;
    return null;
} catch (OutOfMemoryError e) {
    return null;