Android Bitmap Load getBitmapFromFile(File file)

Here you can find the source of getBitmapFromFile(File file)

Description

get Bitmap From File

License

Open Source License

Declaration

public static Bitmap getBitmapFromFile(File file) 

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 ww w  . j a va2s  .c  om
    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 BitmapFactory.Options decodeOptions, final Object cookie, final OnFetchCompleteListener callback)
  2. fetchImage(final Context context, final String url, final OnFetchCompleteListener callback)
  3. getBitmap(Resources resources, int resourceId)
  4. getBitmap(String url, Context context, String newPicName)
  5. getBitmapFromAsset(Context context, String strName)
  6. getBitmapFromFile(String filePath)
  7. getBitmapFromFileInputStream(FileInputStream is)
  8. getBitmapFromRes(Context context, int resId)
  9. getFromUrl(String url)