Java Code Examples for android.graphics.BitmapFactory#decodeResourceStream()
The following examples show how to use
android.graphics.BitmapFactory#decodeResourceStream() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GlideBitmapFactory.java From GlideBitmapPool with Apache License 2.0 | 6 votes |
public static Bitmap decodeResourceStream(Resources res, TypedValue value, InputStream is, Rect pad) { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResourceStream(res, value, is, pad, options); options.inSampleSize = 1; if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) { options.inMutable = true; Bitmap inBitmap = GlideBitmapPool.getBitmap(options.outWidth, options.outHeight, options.inPreferredConfig); if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) { options.inBitmap = inBitmap; } } options.inJustDecodeBounds = false; try { return BitmapFactory.decodeResourceStream(res, value, is, pad, options); } catch (Exception e) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) { options.inBitmap = null; } return BitmapFactory.decodeResourceStream(res, value, is, pad, options); } }
Example 2
Source File: GlideBitmapFactory.java From GlideBitmapPool with Apache License 2.0 | 6 votes |
public static Bitmap decodeResourceStream(Resources res, TypedValue value, InputStream is, Rect pad, int reqWidth, int reqHeight) { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResourceStream(res, value, is, pad, options); options.inSampleSize = Util.calculateInSampleSize(options, reqWidth, reqHeight); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) { options.inMutable = true; Bitmap inBitmap = GlideBitmapPool.getBitmap(options.outWidth, options.outHeight, options.inPreferredConfig); if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) { options.inBitmap = inBitmap; } } options.inJustDecodeBounds = false; try { return BitmapFactory.decodeResourceStream(res, value, is, pad, options); } catch (Exception e) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) { options.inBitmap = null; } return BitmapFactory.decodeResourceStream(res, value, is, pad, options); } }
Example 3
Source File: AccentResources.java From holoaccent with Apache License 2.0 | 5 votes |
private Bitmap getBitmapFromResource(int resId, TypedValue value) { InputStream original = super.openRawResource(resId, value); value.density = getDisplayMetrics().densityDpi; final BitmapFactory.Options options = new BitmapFactory.Options(); options.inDither = false; options.inScaled = false; options.inScreenDensity = getDisplayMetrics().densityDpi; return BitmapFactory.decodeResourceStream( this, value, original, new Rect(), options); }
Example 4
Source File: Fetcher.java From tns-core-modules-widgets with Apache License 2.0 | 4 votes |
/** * Decode and sample down a bitmap from resources to the requested width and height. * * @param res The resources object containing the image data * @param resId The resource id of the image data * @param reqWidth The requested width of the resulting bitmap * @param reqHeight The requested height of the resulting bitmap * @param cache The Cache used to find candidate bitmaps for use with inBitmap * @return A bitmap sampled down from the original with the same aspect ratio and dimensions * that are equal to or greater than the requested width and height */ public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId, int reqWidth, int reqHeight, boolean keepAspectRatio, Cache cache) { // BEGIN_INCLUDE (read_bitmap_dimensions) // First decode with inJustDecodeBounds=true to check dimensions final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(res, resId, options); options.inSampleSize = calculateInSampleSize(options.outWidth, options.outHeight, reqWidth, reqHeight); // END_INCLUDE (read_bitmap_dimensions) // If we're running on Honeycomb or newer, try to use inBitmap if (Utils.hasHoneycomb()) { addInBitmapOptions(options, cache); } // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; Bitmap bitmap = null; InputStream is = null; try { final TypedValue value = new TypedValue(); is = res.openRawResource(resId, value); bitmap = BitmapFactory.decodeResourceStream(res, value, is, null, options); } catch (Exception e) { /* do nothing. If the exception happened on open, bm will be null. If it happened on close, bm is still valid. */ } if (bitmap == null && options != null && options.inBitmap != null) { throw new IllegalArgumentException("Problem decoding into existing bitmap"); } ExifInterface ei = getExifInterface(is); return scaleAndRotateBitmap(bitmap, ei, reqWidth, reqHeight, keepAspectRatio); }
Example 5
Source File: WebpBitmapFactoryImpl.java From fresco with MIT License | 4 votes |
@DoNotStrip private static Bitmap originalDecodeResourceStream( Resources res, TypedValue value, InputStream is, Rect pad, BitmapFactory.Options opts) { return BitmapFactory.decodeResourceStream(res, value, is, pad, opts); }