private Bitmap decodeResource(Resources resources, int id, Request data) { BitmapFactory.Options bitmapOptions = createBitmapOptions(data); if (data.hasSize()) { bitmapOptions.inJustDecodeBounds = true; BitmapFactory.decodeResource(resources, id, bitmapOptions); calculateInSampleSize(data.targetWidth, data.targetHeight, bitmapOptions); } return BitmapFactory.decodeResource(resources, id, bitmapOptions); }
private Bitmap decodeStream(InputStream stream, Request data) throws IOException { if (stream == null) { return null; } MarkableInputStream markStream = new MarkableInputStream(stream); stream = markStream; long mark = markStream.savePosition(MARKER); boolean isWebPFile = Utils.isWebPFile(stream); markStream.reset(mark); // When decode WebP network stream, BitmapFactory throw JNI Exception and make app crash. // Decode byte array instead if (isWebPFile) { byte[] bytes = Utils.toByteArray(stream); BitmapFactory.Options options = createBitmapOptions(data); if (data.hasSize()) { options.inJustDecodeBounds = true; BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options); calculateInSampleSize( data.maxWidth, data.maxHeight, data.targetWidth, data.targetHeight, options); } return BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options); } else { BitmapFactory.Options options = createBitmapOptions(data); if (data.hasSize()) { options.inJustDecodeBounds = true; BitmapFactory.decodeStream(stream, null, options); calculateInSampleSize( data.maxWidth, data.maxHeight, data.targetWidth, data.targetHeight, options); markStream.reset(mark); } return BitmapFactory.decodeStream(stream, null, options); } }
static BitmapFactory.Options createBitmapOptions(Request paramRequest) { boolean bool = paramRequest.hasSize(); if (paramRequest.config != null) {} for (int i = 1; ; i = 0) { Object localObject = null; if ((bool) || (i != 0)) { BitmapFactory.Options localOptions = new BitmapFactory.Options(); localOptions.inJustDecodeBounds = bool; localObject = localOptions; if (i != 0) { localOptions.inPreferredConfig = paramRequest.config; localObject = localOptions; } } return (BitmapFactory.Options) localObject; } }
private Bitmap decodeStream(InputStream stream, Request data) throws IOException { if (stream == null) { return null; } BitmapFactory.Options options = null; if (data.hasSize()) { options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; MarkableInputStream markStream = new MarkableInputStream(stream); stream = markStream; long mark = markStream.savePosition(1024); // Mirrors BitmapFactory.cpp value. BitmapFactory.decodeStream(stream, null, options); calculateInSampleSize(data.targetWidth, data.targetHeight, options); markStream.reset(mark); } return BitmapFactory.decodeStream(stream, null, options); }