List of usage examples for android.graphics BitmapFactory decodeResource
public static Bitmap decodeResource(Resources res, int id, Options opts)
From source file:Main.java
public static Bitmap getBitmapFromResource(Context context, int id, int height, int width) { Options options = new Options(); options.inJustDecodeBounds = true;/* www .j av a 2s. c o m*/ BitmapFactory.decodeResource(context.getResources(), id, options); options.inSampleSize = calculateSampleSize(height, width, options); options.inJustDecodeBounds = false; Bitmap bitmap; bitmap = BitmapFactory.decodeResource(context.getResources(), id, options); return bitmap; }
From source file:Main.java
public static Bitmap drawableTobitmap(int bmpid, Context ctx) { Resources res = ctx.getResources(); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 1;//from w ww . ja v a2 s . c o m return BitmapFactory.decodeResource(res, bmpid, options); }
From source file:Main.java
public static Bitmap getRGB565Bitmap(int resource_id, Context context) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;/*from w w w. j a v a 2 s. com*/ BitmapFactory.decodeResource(context.getResources(), resource_id, options); int ratio = calculateInSampleSize(options, context.getResources().getDisplayMetrics().widthPixels, context.getResources().getDisplayMetrics().heightPixels); options.inSampleSize = ratio; options.inPreferredConfig = Bitmap.Config.RGB_565; options.inJustDecodeBounds = false; options.inPurgeable = true; return BitmapFactory.decodeResource(context.getResources(), resource_id, options); }
From source file:Main.java
public static Bitmap decodeFile(Context context, int resId) { // decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true;//from w ww . j a va2s . co m BitmapFactory.decodeResource(context.getResources(), resId, o); // Find the correct scale value. It should be the power of 2. final int REQUIRED_SIZE = 50; int width_tmp = o.outWidth, height_tmp = o.outHeight; int scale = 1; while (true) { if (width_tmp / 2 < REQUIRED_SIZE || height_tmp / 2 < REQUIRED_SIZE) break; width_tmp /= 2; height_tmp /= 2; scale++; } // decode with inSampleSize BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inSampleSize = scale; return BitmapFactory.decodeResource(context.getResources(), resId, o2); }
From source file:Main.java
public static Bitmap ReadBitmapById(Context mContext, int resId, int mWindth, int mSurfaceHeight) { Options opts = new Options(); opts.outWidth = mWindth;// w w w . j a v a 2 s. c o m opts.outHeight = mSurfaceHeight; Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), resId, opts); return bitmap; }
From source file:Main.java
public static Bitmap decodeQRCode(Resources res, int resId, int inSampleSize) { // First decode with inJustDecodeBounds=true to check dimensions final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;/*from ww w .ja va 2 s . c o m*/ BitmapFactory.decodeResource(res, resId, options); // Calculate inSampleSize options.inSampleSize = inSampleSize; // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeResource(res, resId, options); }
From source file:Main.java
public static Bitmap getBitmapFromName(Context context, String resName) { opt.inPurgeable = true;/*from w w w.ja v a 2s. c om*/ int resID = context.getResources().getIdentifier(resName, "drawable", context.getPackageName()); return BitmapFactory.decodeResource(context.getResources(), resID, opt); }
From source file:Main.java
public static Bitmap decodeSampleBitMapFromResource(Context context, int resId, int reqWidth, int reqHeight) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;//from w w w. j a v a 2s . c o m BitmapFactory.decodeResource(context.getResources(), resId, options); options = sampleBitmapOptions(context, options, reqWidth, reqHeight); Bitmap bm = BitmapFactory.decodeResource(context.getResources(), resId, options); Log.e("xxx", bm.getByteCount() + ""); return bm; }
From source file:Main.java
public static Bitmap imageResourceToBitmap(Context c, int res, int maxDim) { Bitmap bmp = null;/* w w w. j a va 2 s . c om*/ BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; // compute the smallest size bitmap we need to read BitmapFactory.decodeResource(c.getResources(), res, opts); int w = opts.outWidth; int h = opts.outHeight; int s = 1; while (true) { if ((w / 2 < maxDim) || (h / 2 < maxDim)) { break; } w /= 2; h /= 2; s++; } // scale and read the data opts.inJustDecodeBounds = false; opts.inPurgeable = true; opts.inSampleSize = s; bmp = BitmapFactory.decodeResource(c.getResources(), res, opts); return bmp; }
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 w w w .j a v a2 s .co m return BitmapFactory.decodeResource(resources, resourceId, options); }