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

BitmapSafeDecodeBitmapFile( String strFilePath)
Safe Decode Bitmap File
Log.v(TAG, "[ImageDownloader] SafeDecodeBitmapFile : "
        + strFilePath);
try {
    File file = new File(strFilePath);
    if (file.exists() == false) {
        Log.e(TAG,
                "[ImageDownloader] SafeDecodeBitmapFile : File does not exist !!");
        return null;
...
BitmapdecodeF(File f)
Decode f.
Bitmap b = null;
try {
    BitmapFactory.Options bfo = new BitmapFactory.Options();
    FileInputStream fis = new FileInputStream(f);
    b = BitmapFactory.decodeStream(fis, null, bfo);
    fis.close();
} catch (Exception e) {
    e.printStackTrace();
...
BitmapdecodeFile(File f, int size)
See: http://stackoverflow.com/questions/477572/android-strange -out-of-memory-issue-while-loading-an-image -to-a-bitmap-object/823966#823966 Thanks to StackOverflow user named Fedor.
Bitmap b = null;
try {
    BitmapFactory.Options o = new BitmapFactory.Options();
    o.inJustDecodeBounds = true;
    FileInputStream fis = new FileInputStream(f);
    BitmapFactory.decodeStream(fis, null, o);
    fis.close();
    int scale = 1;
...
BitmapdecodeFromDescriptor( FileDescriptor descriptor)
decode From Descriptor
return decodeFromDescriptor(descriptor, 0, 0);
BitmapdecodeFromDescriptor( FileDescriptor descriptor, int reqWidth, int reqHeight)
decode From Descriptor
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFileDescriptor(descriptor, null, options);
options.inSampleSize = inSampleSize(options, reqWidth, reqHeight);
options.inJustDecodeBounds = false;
Bitmap bitmap;
try {
    bitmap = BitmapFactory.decodeFileDescriptor(descriptor, null,
...
BitmapgetBitmap(Context c, String uri, int minsizeDP)
get Bitmap
InputStream input = ContactsContract.Contacts
        .openContactPhotoInputStream(c.getContentResolver(),
                Uri.parse(uri), true);
Bitmap bitmap = BitmapFactory.decodeStream(input);
if (bitmap != null
        && bitmap.getScaledHeight(c.getResources()
                .getDisplayMetrics()) < minsizeDP) {
    int newsize = Math
...
BitmapgetImageFromAssetFile(Context context, String fileName)
get image from assert
Bitmap image = null;
try {
    AssetManager am = context.getAssets();
    InputStream is = am.open(fileName);
    BitmapFactory.Options opt = new BitmapFactory.Options();
    opt.inPreferredConfig = Bitmap.Config.RGB_565;
    opt.inPurgeable = true;
    opt.inInputShareable = true;
...
BooleandownloadImageToSd(String urlSource, String pathDest)
Method
HttpURLConnection mHttpURLConnection = null;
FileOutputStream mFileOutputStream = null;
BufferedOutputStream mBufferedOutputStream = null;
BufferedInputStream mBufferedInputStream = null;
File imageFile = null;
URL url = new URL(urlSource);
mHttpURLConnection = (HttpURLConnection) url.openConnection();
mHttpURLConnection.setConnectTimeout(5 * 1000);
...
BooleandownloadImageToSd(String urlSource, String pathDest, String referer)
download Image To Sd
HttpURLConnection mHttpURLConnection = null;
FileOutputStream mFileOutputStream = null;
BufferedOutputStream mBufferedOutputStream = null;
BufferedInputStream mBufferedInputStream = null;
File imageFile = null;
URL url = new URL(urlSource);
mHttpURLConnection = (HttpURLConnection) url.openConnection();
mHttpURLConnection.setRequestProperty("referer", referer);
...
BitmapgetResizedBitmap(Uri imageUri, Activity activity)
get Resized Bitmap
Bitmap resizedBitmap = null;
try {
    ContentResolver resolver = activity.getContentResolver();
    InputStream in = resolver.openInputStream(imageUri);
    Bitmap bitmap = BitmapFactory.decodeStream(in);
    in.close();
    Matrix matrix = new Matrix();
    DisplayMetrics metrics = new DisplayMetrics();
...