Android Bitmap Load getBitmapFromFile(String filePath)

Here you can find the source of getBitmapFromFile(String filePath)

Description

get Bitmap From File

License

Open Source License

Declaration

public static Bitmap getBitmapFromFile(String filePath) 

Method Source Code

//License from project: Open Source License 

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import org.ixming.android.utils.FrameworkLog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;

public class Main{
    static final String TAG = "sharebind_bitmaputil";
    public static Bitmap getBitmapFromFile(String filePath) {
        return getBitmapFromFile(new File(filePath));
    }/*from  w  w  w.  j  av a2  s  .com*/
    public static Bitmap getBitmapFromFile(File file) {
        FileInputStream fis;
        try {
            fis = new FileInputStream(file);
        } catch (Exception e) {
            FrameworkLog.e(TAG,
                    "getBitmapFromFile Exception: " + e.getMessage());
            return null;
        }
        return getBitmapFromFileInputStream(fis);
    }
    public static Bitmap getBitmapFromFileInputStream(FileInputStream is) {
        if (is == null)
            return null;
        Bitmap bitmap = null;
        try {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inPreferredConfig = Config.RGB_565;
            options.inPurgeable = true;
            options.inInputShareable = true;
            bitmap = BitmapFactory.decodeFileDescriptor(is.getFD(), null,
                    options);
        } catch (Exception e) {
            bitmap = null;
            FrameworkLog.e(TAG, "getBitmapFromFileInputStream Exception: "
                    + e.getMessage());
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (Exception e) {
                }
            }
        }
        return bitmap;
    }
}

Related

  1. fetchImage(final Context context, final String url, final OnFetchCompleteListener callback)
  2. getBitmap(Resources resources, int resourceId)
  3. getBitmap(String url, Context context, String newPicName)
  4. getBitmapFromAsset(Context context, String strName)
  5. getBitmapFromFile(File file)
  6. getBitmapFromFileInputStream(FileInputStream is)
  7. getBitmapFromRes(Context context, int resId)
  8. getFromUrl(String url)
  9. getImageFromUri(Context ctx, Uri uri, int reqWidth, int reqHeight)