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 float getBitmapRatio(Context context, int resourceId) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;/*from   w  ww  . java 2  s.  com*/
    BitmapFactory.decodeResource(context.getResources(), resourceId, options);
    return options.outHeight / (float) options.outWidth;
}

From source file:Main.java

public static Bitmap getBitmapFromResId(Resources res, int resId) {
    opt.inPurgeable = true;
    return BitmapFactory.decodeResource(res, resId, opt);
}

From source file:Main.java

public static void initTexture(Resources res, BitmapFactory.Options opts, int resource, int handle) {
    Bitmap bmp = BitmapFactory.decodeResource(res, resource, opts);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, handle);
    GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bmp, 0);
    GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR_MIPMAP_LINEAR);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
    bmp.recycle();/*www  .  j  a v a  2 s  . c o  m*/
}

From source file:Main.java

/**
 * decode bitmap from resource id.// w  w  w  .j  a  v  a  2 s .c  om
 */
public static Bitmap res2bitmap(int resId) {
    return BitmapFactory.decodeResource(sApp.getResources(), resId, null);
}

From source file:Main.java

public static BitmapFactory.Options getSize(Context c, int resId) {
    android.graphics.BitmapFactory.Options o = new android.graphics.BitmapFactory.Options();
    o.inJustDecodeBounds = true;/*w ww.  ja  va 2s .  c  o m*/
    BitmapFactory.decodeResource(c.getResources(), resId, o);
    return o;
}

From source file:Main.java

/** Get Bitmap's height **/
public static int getBitmapOfHeight(Resources res, int id) {
    try {/*from  w w w .j a  va 2s. c o m*/
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeResource(res, id, options);
        return options.outHeight;
    } catch (Exception e) {
        return 0;
    }
}

From source file:Main.java

private static Bitmap loadBitmapFromResources(Context context, int resourceId) {
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inScaled = false;//from   w  w w .j  av a  2s  . c  o  m

    // Read in the resource
    return BitmapFactory.decodeResource(context.getResources(), resourceId, options);
}

From source file:Main.java

public static Bitmap loadBitmapFromRaw(Context context, int resourceId) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inScaled = false;/*w  ww . j  a v  a2  s.  c  om*/
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, options);
    return bitmap;
}

From source file:Main.java

public static Bitmap LOAD_IMAGE(Resources res, int scaling, int id) {
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = false;/*from  w  ww . j  a v  a 2  s . co m*/
    options.inSampleSize = scaling;
    return BitmapFactory.decodeResource(res, id, options);
}

From source file:Main.java

public static Bitmap readBitmapFormSrc(Context context, int src, float width, float height, int pixels) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;// w  w  w.  ja v a 2  s  . c  o  m
    BitmapFactory.decodeResource(context.getResources(), src, options);
    options.inSampleSize = calculateInSampleSize(options, width, height, pixels);
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeResource(context.getResources(), src, options);
}