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 decodeResource(Context context, int id, BitmapFactory.Options options) { Resources resources = context.getResources(); try {/*from w w w .ja va 2 s. co m*/ return BitmapFactory.decodeResource(resources, id, options); } catch (OutOfMemoryError e) { Log.e(LOGTAG, "decodeResource() OOM! Resource id=" + id, e); return null; } }
From source file:Main.java
public static Bitmap decodeSampledBitmapFromRes(Context context, int id, int reqWidth, int reqHeight) { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;/*from w w w . j av a 2s . c om*/ BitmapFactory.decodeResource(context.getResources(), id, options); options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); options.inJustDecodeBounds = false; return BitmapFactory.decodeResource(context.getResources(), id, options); }
From source file:Main.java
public static Bitmap getSmallBmpFromResource(Context context, int id, int targetW, int targetH) { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;//from w ww . j a va 2s.c o m BitmapFactory.decodeResource(context.getResources(), id, options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, targetW, targetH); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeResource(context.getResources(), id, options); }
From source file:Main.java
public static Bitmap getFitSampleBitmap(Resources resources, int resId, int width, int height) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;/*from w w w .java 2 s.c om*/ BitmapFactory.decodeResource(resources, resId, options); options.inSampleSize = getFitInSampleSize(width, height, options); options.inJustDecodeBounds = false; return BitmapFactory.decodeResource(resources, resId, options); }
From source file:Main.java
public static Bitmap decodeBitmapFromResource(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;//from ww w.ja v 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
protected static int bindTexture(Context context, int drawable) { BitmapFactory.Options option = new BitmapFactory.Options(); option.inScaled = false;/*from w ww . j ava 2 s . c o m*/ return bindTexture(BitmapFactory.decodeResource(context.getResources(), drawable, option)); }
From source file:Main.java
/** * toSpannableString/* www . j a va 2s . c om*/ * @return SpannableString * @throws */ public static SpannableString toSpannableString(Context context, String text) { if (!TextUtils.isEmpty(text)) { SpannableString spannableString = new SpannableString(text); int start = 0; Pattern pattern = Pattern.compile("\\\\ue[a-z0-9]{3}", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(text); while (matcher.find()) { String faceText = matcher.group(); String key = faceText.substring(1); BitmapFactory.Options options = new BitmapFactory.Options(); Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), context.getResources().getIdentifier(key, "drawable", context.getPackageName()), options); ImageSpan imageSpan = new ImageSpan(context, bitmap); int startIndex = text.indexOf(faceText, start); int endIndex = startIndex + faceText.length(); if (startIndex >= 0) spannableString.setSpan(imageSpan, startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); start = (endIndex - 1); } return spannableString; } else { return new SpannableString(""); } }
From source file:Main.java
public static Bitmap decodeInSampleSize(Resources res, int resId, int reqWidth, int reqHeight) { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;// w w w . j a va 2 s .c om BitmapFactory.decodeResource(res, resId, options); options.inSampleSize = calculateSize(options, reqWidth, reqHeight); options.inJustDecodeBounds = false; return BitmapFactory.decodeResource(res, resId, options); }
From source file:Main.java
/** * Retrieve a bitmap that can be used for comparison on any density * @param resources//from w ww. j ava 2s.co m * @return the {@link Bitmap} or <code>null</code> */ public static Bitmap getUnscaledBitmap(Resources resources, int resId) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inScaled = false; return BitmapFactory.decodeResource(resources, resId, options); }
From source file:Main.java
/** * @param imageResId/*from w w w . ja v a2 s .com*/ * @return */ public static int[] getActualImageDimension(Context context, int imageResId) { int[] imageSize = new int[2]; BitmapFactory.Options decodeOptions = new BitmapFactory.Options(); // If we have to resize this image, first get the natural bounds. decodeOptions.inJustDecodeBounds = true; BitmapFactory.decodeResource(context.getResources(), imageResId, decodeOptions); int actualWidth = decodeOptions.outWidth; int actualHeight = decodeOptions.outHeight; imageSize[0] = actualWidth; imageSize[1] = actualHeight; return imageSize; }