Android Bitmap Load getTempBitmap(Context context)

Here you can find the source of getTempBitmap(Context context)

Description

get Temp Bitmap

Declaration

public static Bitmap getTempBitmap(Context context) 

Method Source Code

//package com.java2s;

import java.io.File;

import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.graphics.Bitmap;

import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Environment;

public class Main {
    public static Bitmap getTempBitmap(Context context) {
        Bitmap capturedBitmap = null;/*from   w  w  w.j a v  a  2 s  .  c om*/
        final File file = getTempFile(context);
        try {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inSampleSize = 4;

            AssetFileDescriptor fileDescriptor = context
                    .getContentResolver().openAssetFileDescriptor(
                            Uri.fromFile(file), "r");
            capturedBitmap = BitmapFactory.decodeFileDescriptor(
                    fileDescriptor.getFileDescriptor(), null, options);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return capturedBitmap;
    }

    public static File getTempFile(Context context) {
        // It will return /sdcard/image.tmp
        final File path = new File(
                Environment.getExternalStorageDirectory(),
                context.getPackageName());
        if (!path.exists()) {
            path.mkdir();
        }
        return new File(path, "image.tmp");
    }
}

Related

  1. getBitmapFromUrl(String url)
  2. loadBitmapFromFile(String fileNameWithPath)
  3. downloadBitmap(URI uri)
  4. returnBitMap(String path)
  5. getBitmapStoragePath(Context context)
  6. createBitmapFromImageFile(File imagefile)