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) 

Source Link

Document

Synonym for #decodeResource(Resources,int,android.graphics.BitmapFactory.Options) with null Options.

Usage

From source file:Main.java

public static int getImageHeight(final Context context, final int drawable) {
    int bg_height = 0;
    Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), drawable);
    bg_height = bmp.getHeight();//from   w w w  .  ja  v  a 2s  . co m
    bmp.recycle();
    return bg_height;
}

From source file:Main.java

public static Bitmap loadBitmapRes(Context context, int res) {
    Bitmap bitmap = null;//from   w w w  .  j a va  2 s. c o m
    try {
        bitmap = BitmapFactory.decodeResource(context.getResources(), res);
    } catch (Exception e) {
        e.printStackTrace();
    } catch (OutOfMemoryError e) {
        e.printStackTrace();
    }
    return bitmap;
}

From source file:Main.java

public static int[] getImageSize(Context context, int drawableId) {
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), drawableId);
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    if (bitmap != null && bitmap.isRecycled()) {
        bitmap.recycle();//  w w w .  j  av a 2s .  c  o m
    }
    int size[] = { width, height };
    return size;
}

From source file:Main.java

public static Bitmap getBitmapFromResources(Activity act, int resId) {
    Resources res = act.getResources();
    return BitmapFactory.decodeResource(res, resId);
}

From source file:Main.java

public static Bitmap getResBitmap(Context context, int resId) {
    Resources res = context.getResources();
    return BitmapFactory.decodeResource(res, resId);
}

From source file:Main.java

public static Bitmap getImageFromResourcde(Context ctx, int drawableResource) {
    // e.g. R.drawable.watermelon
    try {/*from www .  j av  a  2s.  c o m*/
        Bitmap image = BitmapFactory.decodeResource(ctx.getResources(), drawableResource);
        return image;
    } catch (Exception e) {
        return null;
    }
}

From source file:Main.java

public static Bitmap fetchBitmapFromRes(Context context, int resId) {
    Resources res = context.getResources();
    Bitmap bmp = BitmapFactory.decodeResource(res, resId);
    return bmp;/*  w w w  . ja v a2  s. co  m*/
}

From source file:Main.java

public static Point getImageDimension(Context context, int resource) {
    Bitmap bm = BitmapFactory.decodeResource(context.getResources(), resource);
    Point point = new Point();
    point.x = bm.getWidth();/*from   w w  w.ja  va2s  .co  m*/
    point.y = bm.getHeight();
    bm.recycle();
    bm = null;

    return point;
}

From source file:Main.java

public static Bitmap resource2Bitmap(Context context, int picId) {
    Bitmap bmp = null;//from w  w  w. j  a v  a2 s.co m
    try {
        bmp = BitmapFactory.decodeResource(context.getResources(), picId);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return bmp;
}

From source file:Main.java

public static Bitmap decodeFromResource(Context context, int id) {
    Resources res = context.getResources();
    Bitmap bitmap = BitmapFactory.decodeResource(res, id).copy(Bitmap.Config.ARGB_8888, true);
    return bitmap;
}