Example usage for android.graphics BitmapFactory decodeResource

List of usage examples for android.graphics BitmapFactory decodeResource

Introduction

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

Prototype

public static Bitmap decodeResource(Resources res, int id, Options opts) 

Source Link

Document

Synonym for opening the given resource and calling #decodeResourceStream .

Usage

From source file:Main.java

public static Bitmap scaleImage(Resources resources, int resId, int maxSize) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;/*from   w  w  w . j  a v a 2 s .  co m*/
    BitmapFactory.decodeResource(resources, resId, options);
    options.inSampleSize = calculateInSampleSize(options, maxSize, maxSize);
    options.inJustDecodeBounds = false;

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

From source file:Main.java

public static Bitmap decodeBitmapFromResource(Resources resource, int resId, int reqWidth, int reqHeight) {
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;/* ww w .  j  a v a  2s.c o m*/
    BitmapFactory.decodeResource(resource, resId, options);
    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
    Log.e("BitmapUtils", "inSampleSize = " + options.inSampleSize);
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeResource(resource, resId, options);
}

From source file:Main.java

public static Bitmap decodeBitmapFromResource(Config config, Resources res, int resId, int reqWidth,
        int reqHeight) {

    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;/*w  w w.ja  va 2  s .  c  o  m*/
    BitmapFactory.decodeResource(res, resId, options);

    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
    options.inJustDecodeBounds = false;
    options.inPreferredConfig = config;

    return BitmapFactory.decodeResource(res, resId, options);
}

From source file:Main.java

public static Bitmap decodeBitmapFromResource(Resources resources, int rId, int reqWidth, int reqHeight) {
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;// w  w w.j  ava  2 s  .  c  o m
    options.inPreferredConfig = Bitmap.Config.RGB_565;

    BitmapFactory.decodeResource(resources, rId, options);
    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

    options.inJustDecodeBounds = false;

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

From source file:Main.java

public static int loadTexture(final Context context, final int resourceId) {
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inScaled = false; // No pre-scaling
    final Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, options);

    return loadTexture(bitmap);
}

From source file:Main.java

/**
 * Allows to get a bitmap (SCALED, i.e SHARP) from the resources
 * @param _res//from w  ww.  j  av a  2  s.  c o  m
 * @param _resId
 * @return
 */
public static Bitmap getScaledResourceBitmap(Resources _res, int _resId) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inScaled = false;
    return BitmapFactory.decodeResource(_res, _resId, options);
}

From source file:Main.java

public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId, int reqWidth, int reqHeight) {

    // First decode with inJustDecodeBounds=true to check dimensions
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;// w w w. j  a va 2  s . com
    BitmapFactory.decodeResource(res, resId, options);

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

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeResource(res, resId, options);
}

From source file:Main.java

public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId, int reqWidth, int reqHeight) {

    // First decode with inJustDecodeBounds=true to check dimensions
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;/* w w  w.  java  2 s  . c o m*/
    options.inPurgeable = true;
    BitmapFactory.decodeResource(res, resId, options);

    if (options.outHeight > 0 && options.outWidth > 0) {
        // Calculate inSampleSize
        options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

        // Decode bitmap with inSampleSize set
        options.inJustDecodeBounds = false;
        return BitmapFactory.decodeResource(res, resId, options);
    } else {
        return null;
    }
}

From source file:Main.java

public static Bitmap decodeBitmapFromResource(Resources res, int resId, int reqWidth, int reqHeight) {
    // First decode with <code>inJustDecodeBounds = true</code> to check dimensions.
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;//from   ww w. j  av a2 s  .c  o  m
    BitmapFactory.decodeResource(res, resId, options);

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

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeResource(res, resId, options);
}

From source file:Main.java

public static Bitmap getFlippedBitmap(Resources res, int resId) {

    BitmapFactory.Options opt = new BitmapFactory.Options();
    opt.inJustDecodeBounds = true;/*from w  w  w .  j a  va2  s . c  o  m*/
    //Below line is necessary to fill in opt.outWidth, opt.outHeight
    Bitmap b = BitmapFactory.decodeResource(res, resId, opt);

    b = Bitmap.createBitmap(opt.outWidth, opt.outHeight, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(b);

    Matrix flipHorizontalMatrix = new Matrix();
    flipHorizontalMatrix.setScale(-1, 1);
    flipHorizontalMatrix.postTranslate(b.getWidth(), 0);

    Bitmap bb = BitmapFactory.decodeResource(res, resId);
    canvas.drawBitmap(bb, flipHorizontalMatrix, null);

    return b;
}