Example usage for android.graphics BitmapFactory.Options BitmapFactory.Options

List of usage examples for android.graphics BitmapFactory.Options BitmapFactory.Options

Introduction

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

Prototype

BitmapFactory.Options

Source Link

Usage

From source file:Main.java

public static BitmapFactory.Options getBitmapDimesions(byte[] img) {

    // Make sure the bitmap is not stored in memory!
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;/*from   ww w  .j av a2  s.com*/

    BitmapFactory.decodeByteArray(img, 0, img.length, options);

    return options;
}

From source file:Main.java

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

    return (options.outMimeType != null);
}

From source file:Main.java

public static Bitmap loadResource(Context context, int resourceId) {

    Resources resources = context.getResources();

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inDensity = resources.getDisplayMetrics().densityDpi;
    options.inPurgeable = true;/*from   ww  w. j  av a  2  s. c om*/

    return BitmapFactory.decodeResource(resources, resourceId, options);
}

From source file:Main.java

public static final Bitmap getBitmapFromRaw(Context context, int resId) {
    if (resId <= 0)
        return null;
    try {/*  w  w w.  j  a v a  2  s  .  c o  m*/
        InputStream is = context.getResources().openRawResource(resId);
        BitmapFactory.Options imageOptions = new BitmapFactory.Options();
        Bitmap bmp = BitmapFactory.decodeStream(is, null, imageOptions);
        return bmp;
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static BitmapFactory.Options getBitmapSize(String strImagePath) {
    //==========================================
    // Loaded the temporary bitmap for getting size.
    //==========================================
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;//from   www  .  j  a  v  a2 s  .  c  o m
    //Bitmap photo = BitmapFactory.decodeFile(strPath, options);
    BitmapFactory.decodeFile(strImagePath, options);

    return options;
}

From source file:Main.java

public static final Bitmap getBitmapFromUri(Context context, Uri uri) {
    if (uri == null)
        return null;
    try {//from w w w  .j  a  va  2 s.c o  m
        InputStream is = context.getContentResolver().openInputStream(uri);
        BitmapFactory.Options imageOptions = new BitmapFactory.Options();
        Bitmap bmp = BitmapFactory.decodeStream(is, null, imageOptions);
        return bmp;
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static final boolean checkImageAndSize(Context context, Uri uri, long bytes) {
    if (uri == null)
        return false;

    try {//from  www.  ja v  a  2 s  . c  o m
        InputStream is = context.getContentResolver().openInputStream(uri);
        BitmapFactory.Options imageOptions = new BitmapFactory.Options();
        imageOptions.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(is, null, imageOptions);
        //android.util.Log.d("test77", "Original Image Size: " + imageOptions.outWidth + " x " + imageOptions.outHeight);
        is.close();
        if (imageOptions.outWidth <= 0 || imageOptions.outHeight <= 0) {
            return false;
        }
        is = context.getContentResolver().openInputStream(uri);
        long fileSizeCounter = 0;
        long size;
        byte[] buf = new byte[8192];
        while ((size = is.read(buf, 0, buf.length)) != -1) {
            //android.util.Log.d("test77", "size="+size);
            fileSizeCounter += size;
        }
        is.close();
        if (fileSizeCounter > bytes) {
            return false;
        }
        return true;
    } catch (Exception ex) {
        ex.printStackTrace();
        return false;
    }
}

From source file:Main.java

public static BitmapFactory.Options getBitmapSize(String strImagePath, boolean checkOrientation) {
    //==========================================
    // Loaded the temporary bitmap for getting size.
    //==========================================
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;/*ww  w .j a v  a  2  s . c  o  m*/
    //Bitmap photo = BitmapFactory.decodeFile(strPath, options);
    BitmapFactory.decodeFile(strImagePath, options);

    if (checkOrientation) {
        int degree = getExifDegree(strImagePath);
        if (degree == 90 || degree == 270) {
            int temp = options.outWidth;
            options.outWidth = options.outHeight;
            options.outHeight = temp;
        }
    }

    return options;
}

From source file:Main.java

public static final Bitmap getBitmapFromUri(Context context, Uri uri, int maxWidth, int maxHeight) {
    if (uri == null)
        return null;
    try {// www  .ja v  a2  s  .c  om
        InputStream is = context.getContentResolver().openInputStream(uri);

        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        // Set height and width in options, does not return an image and no resource taken
        BitmapFactory.decodeStream(is, null, options);
        int pow = 0;
        while (options.outHeight >> pow > maxHeight || options.outWidth >> pow > maxWidth) {
            pow += 1;
        }
        is.close();
        is = context.getContentResolver().openInputStream(uri);
        options.inSampleSize = 1 << pow;
        options.inJustDecodeBounds = false;
        Bitmap bmp = BitmapFactory.decodeStream(is, null, options);

        return bmp;
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }
}

From source file:Main.java

/**
 * Creates a <tt>Bitmap</tt> from the given image byte array and scales
 * it to the given <tt>width</tt> and <tt>height</tt>.
 *
 * @param imageBytes the raw image data/*from  ww  w.  j av a  2  s  .  c o m*/
 * @param reqWidth the width to which to scale the image
 * @param reqHeight the height to which to scale the image
 * @return the newly created <tt>Bitmap</tt>
 */
static public Bitmap scaledBitmapFromBytes(byte[] imageBytes, int reqWidth, int reqHeight) {
    // First decode with inJustDecodeBounds=true to check dimensions
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length, options);

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

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length, options);
}