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 boolean checkImgCorrupted(String filePath) {
    BitmapFactory.Options options = null;
    if (options == null) {
        options = new BitmapFactory.Options();
    }/* ww  w . j a v  a 2  s. com*/
    options.inJustDecodeBounds = true;

    BitmapFactory.decodeFile(filePath, options);
    if (options.mCancel || options.outWidth == -1 || options.outHeight == -1) {
        return true;
    }
    return false;
}

From source file:Main.java

public static Bitmap resizeBitmap(String photoPath, int maxSide) {
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    bmOptions.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(photoPath, bmOptions);
    int photoW = bmOptions.outWidth;
    int photoH = bmOptions.outHeight;

    boolean landscape = true;
    if (photoW < photoH) {
        // portrait
        landscape = false;/*w  w  w  . j a va 2  s.  c om*/
    }

    int scaleFactor = 1;
    if (landscape) {
        scaleFactor = photoW / maxSide;
    } else {
        scaleFactor = photoH / maxSide;
    }

    bmOptions.inJustDecodeBounds = false;
    bmOptions.inSampleSize = scaleFactor;
    bmOptions.inPurgeable = true;

    return BitmapFactory.decodeFile(photoPath, bmOptions);
}

From source file:Main.java

private static Bitmap getDecodeAbleBitmap(String picturePath) {
    try {//from  w  w w. j av  a  2 s.  com
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(picturePath, options);
        int sampleSize = options.outHeight / 400;
        if (sampleSize <= 0)
            sampleSize = 1;
        options.inSampleSize = sampleSize;
        options.inJustDecodeBounds = false;

        return BitmapFactory.decodeFile(picturePath, options);
    } catch (Exception e) {
        return null;
    }
}

From source file:Main.java

public static Bitmap getSmallBitmap(String filePath) {
    final Options options = new Options();
    options.inJustDecodeBounds = true;//  www.ja  va 2s .  co m
    BitmapFactory.decodeFile(filePath, options);

    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, 480, 800);

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;

    return BitmapFactory.decodeFile(filePath, options);
}

From source file:Main.java

public static int[] getBitmapSizeFromPath(String filePath) {
    // First decode with inJustDecodeBounds=true to check dimensions
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;/*w ww .ja v  a2  s .com*/

    BitmapFactory.decodeFile(filePath, options);
    int[] array = new int[2];
    array[0] = options.outWidth;
    array[1] = options.outHeight;
    return array;
}

From source file:Main.java

public static Bitmap decodeSampledBitmap(String path, int reqWidth, int reqHeight) {

    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;/*from w w w.j  a va 2s .c  o  m*/
    BitmapFactory.decodeFile(path, options);
    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeFile(path, options);
}

From source file:Main.java

public static Bitmap getLoacalBitmap(String url, int sampleSize) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = false;//from  w  ww .  j  a va  2s  . c o m
    options.inSampleSize = sampleSize;
    return BitmapFactory.decodeFile(url, options);
}

From source file:Main.java

public static Bitmap getBitFromPath(String path) {
    BitmapFactory.Options options = new BitmapFactory.Options();

    options.inPreferredConfig = Config.ARGB_8888;

    Bitmap img = BitmapFactory.decodeFile(path, options);
    return img;//w  w w  .  j av  a  2s .  c om
}

From source file:Main.java

public static Bitmap loadResBitmap(String path, int scaleSize) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = false;//from   w  w  w  . ja va 2 s.com
    options.inSampleSize = scaleSize;
    Bitmap bmp = BitmapFactory.decodeFile(path, options);
    return bmp;
}

From source file:Main.java

public static Bitmap decodeSampledBitmapFromSd(String pathName, int reqWidth, int reqHeight) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;// w  w  w. j a  v  a  2  s. c  o  m
    BitmapFactory.decodeFile(pathName, options);
    options.inSampleSize = caculateInSampleSize(options, reqWidth, reqHeight);
    options.inJustDecodeBounds = false;
    Bitmap src = BitmapFactory.decodeFile(pathName, options);
    return createScaleBitmap(src, reqWidth, reqHeight);
}