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 BitmapFactory.Options getOptionsFromFile(String filePath) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;/*w w w.  ja  v a  2s  .co  m*/
    BitmapFactory.decodeFile(filePath, options);
    return options;
}

From source file:Main.java

public static Bitmap getCompressedBitmap(String path) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;//from ww w  .  j  a  va  2 s .  co m
    BitmapFactory.decodeFile(path, options);
    options.inSampleSize = calculateInSampleSize(options, 480, 800);
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeFile(path, options);
}

From source file:Main.java

public static int getNbPixels(String imagePath) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;// www  .  j a v  a2  s  .  c o m

    //Returns null, sizes are in the options variable
    BitmapFactory.decodeFile(imagePath, options);
    int width = options.outWidth;
    int height = options.outHeight;

    return width * height;
}

From source file:Main.java

public final static BitmapFactory.Options getBitmapOptions(String srcPath) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;//from   w  w  w. j  a v  a 2s  .com
    BitmapFactory.decodeFile(srcPath, options);
    return options;
}

From source file:Main.java

/** Get Bitmap's Width **/
public static int getBitmapOfWidth(String fileName) {
    try {//from www . j ava 2 s.c o  m
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(fileName, options);
        return options.outWidth;
    } catch (Exception e) {
        return 0;
    }
}

From source file:Main.java

public static Bitmap getSmallBitmap(String filePath) {
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;/*from   w  w w  . j  av  a 2s.  c o m*/
    BitmapFactory.decodeFile(filePath, options);

    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, 200, 200);

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

From source file:Main.java

public static Options getBitmapOptionsWithSize(String path) {
    Options options = new Options();
    options.inJustDecodeBounds = true;/*from w  ww.  ja  v a2  s . co m*/
    BitmapFactory.decodeFile(path, options);
    options.inJustDecodeBounds = false;
    return options;
}

From source file:Main.java

/** Get Bitmap's height **/
public static int getBitmapOfHeight(String fileName) {
    try {//w w  w.j av a  2  s.  c  o  m
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(fileName, options);

        return options.outHeight;
    } catch (Exception e) {
        return 0;
    }
}

From source file:Main.java

public static boolean isBitmapEmpty(String path) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 1;// w  w w .ja  v  a  2  s.co  m
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(path, options);
    return options.outHeight <= 0 || options.outWidth <= 0;
}

From source file:Main.java

public static boolean isValidImagePath(String strImagePath) {
    if (strImagePath == null) {
        return false;
    }//from  w  w  w.ja v a 2s  .  c o  m
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(strImagePath, options);

    return (options.outMimeType != null);
}