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 getBitmapZoom480800(String filePath) {
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;// ww  w  .j  a v  a  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 Bitmap getSmallBitmap(String filePath) {
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;//ww w  .  ja  va 2 s.  com
    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 Bitmap createThumbnail(String filePath, int newWidth, int newHeight) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;//from  ww w. j  a v a 2s  .co m
    BitmapFactory.decodeFile(filePath, options);
    int originalWidth = options.outWidth;
    int originalHeight = options.outHeight;
    int ratioWidth = originalWidth / newWidth;
    int ratioHeight = originalHeight / newHeight;
    options.inSampleSize = ratioHeight > ratioWidth ? ratioHeight : ratioWidth;
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeFile(filePath, options);
}

From source file:Main.java

public static Bitmap getScaleBitmap(Context context, String filePath) {
    BitmapFactory.Options opts = new BitmapFactory.Options();
    opts.inSampleSize = 4;//w  w w.  j av  a2  s. co m

    return BitmapFactory.decodeFile(filePath, opts);
}

From source file:Main.java

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

    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, 540, 960);

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

    return BitmapFactory.decodeFile(filePath, options);
}

From source file:Main.java

public static Bitmap readBitmap(String path) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;//www. jav a  2  s.c o  m
    BitmapFactory.decodeFile(path, options);
    if (options.mCancel || options.outWidth == -1 || options.outHeight == -1) {
        return null;
    }
    options.inSampleSize = computeSampleSize(options, 600, (int) (0.5 * 1024 * 1024));
    options.inJustDecodeBounds = false;
    options.inDither = false;
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
    Bitmap bitmap = BitmapFactory.decodeFile(path, options);
    return bitmap;
}

From source file:Main.java

private static int getScale(String imagePath, int desiredWidth, int desiredHeight) {
    //Get image size
    BitmapFactory.Options imageInfo = new BitmapFactory.Options();
    imageInfo.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(imagePath, imageInfo);

    //Compute the scaling factor
    int scale = 1;
    int width = imageInfo.outWidth;
    int height = imageInfo.outHeight;

    while (width / (scale * 2) >= desiredWidth && height / (scale * 2) >= desiredHeight) {
        scale = scale * 2;//from   w ww.  j  av a  2s  . c o m
    }

    return scale;
}

From source file:Main.java

public static Bitmap getSmallBitmap(String filePath, int width, int height) {
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;/*w ww  .j a  v  a  2 s  . com*/
    BitmapFactory.decodeFile(filePath, options);
    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, width, height);
    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeFile(filePath, options);
}

From source file:Main.java

public static int[] decodeImageSize(String filePath) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;/*www  .ja v  a  2  s.c o  m*/
    options.inDither = false;
    BitmapFactory.decodeFile(filePath, options);
    return new int[] { options.outWidth, options.outHeight };
}

From source file:Main.java

public static Bitmap compressBitmap(String filePath, int with, int height) {
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;/*from w  w w.ja  va 2 s  .  co m*/
    BitmapFactory.decodeFile(filePath, options);

    options.inSampleSize = calculateInSampleSize(options, with, height);
    options.inJustDecodeBounds = false;

    return BitmapFactory.decodeFile(filePath, options);
}