Example usage for android.graphics BitmapFactory decodeFile

List of usage examples for android.graphics BitmapFactory decodeFile

Introduction

In this page you can find the example usage for android.graphics BitmapFactory decodeFile.

Prototype

public static Bitmap decodeFile(String pathName, Options opts) 

Source Link

Document

Decode a file path into a bitmap.

Usage

From source file:Main.java

public static Bitmap getSampledBitmap(String filePath, int reqWidth, int reqHeight) {
    Options options = new Options();
    options.inJustDecodeBounds = true;/* www . j ava  2 s  .  c o  m*/

    BitmapFactory.decodeFile(filePath, options);

    // Raw height and width of image
    final int height = options.outHeight;
    final int width = options.outWidth;
    int inSampleSize = 1;

    if (height > reqHeight || width > reqWidth) {
        if (width > height) {
            inSampleSize = (int) Math.floor(((float) height / reqHeight) + 0.5f); // Math.round((float)height
            // /
            // (float)reqHeight);
        } else {
            inSampleSize = (int) Math.floor(((float) width / reqWidth) + 0.5f); // Math.round((float)width
            // /
            // (float)reqWidth);
        }
    }
    // System.out.println("inSampleSize--->"+inSampleSize);

    options.inSampleSize = inSampleSize;
    options.inJustDecodeBounds = false;

    return BitmapFactory.decodeFile(filePath, options);
}

From source file:Main.java

public static Bitmap decodeBitmap(Context context, String pathName) {
    checkParam(context);
    return BitmapFactory.decodeFile(pathName, getBitmapOptions(context));
}

From source file:Main.java

/**
 * Decode and sample down a bitmap from a file to the requested width and height.
 *
 * @param filename  The full path of the file to decode
 * @param reqWidth  The requested width of the resulting bitmap
 * @param reqHeight The requested height of the resulting bitmap
 * @return A bitmap sampled down from the original with the same aspect ratio and dimensions
 * that are equal to or greater than the requested width and height
 *///from  w w  w .  j  a va  2 s .  co  m
public static Bitmap decodeSampledBitmapFromFile(String filename, int reqWidth, int reqHeight) {

    // First decode with inJustDecodeBounds=true to check dimensions
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(filename, options);

    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeFile(filename, options);
}

From source file:Main.java

public static Bitmap getThumbnail(Context context, String url) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;/* w  ww  .ja  v a  2s  .  c  o  m*/
    BitmapFactory.decodeFile(url, options);

    float w = options.outWidth;
    float h = options.outHeight;
    float max = Math.max(w, h);

    BitmapFactory.Options bounds = new BitmapFactory.Options();
    bounds.inPurgeable = true;
    bounds.inInputShareable = true;
    bounds.inJustDecodeBounds = false;

    float size = max / 800;
    if (size > 1) {
        bounds.inSampleSize = (int) size;
    }
    return BitmapFactory.decodeFile(url, bounds);
}

From source file:Main.java

public static Bitmap decodeSampledBitmapFromFilePath(String filePath, int reqWidth, int reqHeight) {

    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;/*from  w ww  .  jav  a  2s. c  o m*/
    BitmapFactory.decodeFile(filePath, options);

    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeFile(filePath, options);
}

From source file:Main.java

public static Bitmap getBitmap(String bitmapPath) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    return BitmapFactory.decodeFile(bitmapPath, options);
}

From source file:Main.java

public static Bitmap getPictureImage(String urlPath) {
    Bitmap bitmap = null;/* w  ww . j  a v a2s  .  co m*/
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    bitmap = BitmapFactory.decodeFile(urlPath, options);
    options.inJustDecodeBounds = false;
    int h = options.outHeight;
    int w = options.outWidth;
    int beWidth = w / 100;
    int beHeight = h / 80;
    int be = 1;
    if (beWidth < beHeight) {
        be = beWidth;
    } else {
        be = beHeight;
    }
    if (be <= 0) {
        be = 1;
    }
    options.inSampleSize = be;
    bitmap = BitmapFactory.decodeFile(urlPath, options);
    bitmap = ThumbnailUtils.extractThumbnail(bitmap, 100, 80, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
    return bitmap;
}

From source file:Main.java

public static Bitmap getBitmapScaledToDisplay(File f, int screenHeight, int screenWidth) {
    // Determine image size of f
    BitmapFactory.Options o = new BitmapFactory.Options();
    o.inJustDecodeBounds = true;/*  w  w w.  ja  va2  s .c  om*/
    BitmapFactory.decodeFile(f.getAbsolutePath(), o);

    int heightScale = o.outHeight / screenHeight;
    int widthScale = o.outWidth / screenWidth;

    // Powers of 2 work faster, sometimes, according to the doc.
    // We're just doing closest size that still fills the screen.
    int scale = Math.max(widthScale, heightScale);

    // get bitmap with scale ( < 1 is the same as 1)
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inInputShareable = true;
    options.inPurgeable = true;
    options.inSampleSize = scale;
    Bitmap b = BitmapFactory.decodeFile(f.getAbsolutePath(), options);
    if (b != null) {
        Log.i(t, "Screen is " + screenHeight + "x" + screenWidth + ".  Image has been scaled down by " + scale
                + " to " + b.getHeight() + "x" + b.getWidth());
    }
    return b;
}

From source file:Main.java

public static int[] decodeBitmapSize(File file) {
    // First decode with inJustDecodeBounds=true to check dimensions
    final Options options = new Options();
    options.inScaled = false;//from   w w  w .j a  v  a 2 s .c om
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(file.getAbsolutePath(), options);
    return new int[] { options.outWidth, options.outHeight };
}

From source file:Main.java

public static Bitmap decodeScaleImage(String imagePath, int outWidth, int outHeight) {
    BitmapFactory.Options localOptions = new BitmapFactory.Options();
    localOptions.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(imagePath, localOptions);
    int i = calculateInSampleSize(localOptions, outWidth, outHeight);
    localOptions.inSampleSize = i;//from ww  w . j  a v a 2  s  . c  o m
    localOptions.inJustDecodeBounds = false;
    Bitmap localBitmap1 = BitmapFactory.decodeFile(imagePath, localOptions);
    int j = getPictureDegree(imagePath);
    Bitmap localBitmap2 = null;
    if ((localBitmap1 != null) && (j != 0)) {
        localBitmap2 = rotaingImageView(j, localBitmap1);
        localBitmap1.recycle();
        localBitmap1 = null;
        return localBitmap2;
    }
    return localBitmap1;
}