/** * @deprecated Use {@link #obtain(Resources, Resource)} instead, it can be unsafe to extract * {@link Bitmap}s from their wrapped {@link Resource}. */ @Deprecated public static LazyBitmapDrawableResource obtain(Resources resources, BitmapPool bitmapPool, Bitmap bitmap) { return (LazyBitmapDrawableResource) obtain(resources, BitmapResource.obtain(bitmap, bitmapPool)); }
@Override public Resource<Bitmap> decode(@NonNull GifDecoder source, int width, int height, @NonNull Options options) { Bitmap bitmap = source.getNextFrame(); return BitmapResource.obtain(bitmap, bitmapPool); } }
@Override public Resource<Bitmap> answer(InvocationOnMock invocationOnMock) throws Throwable { return BitmapResource.obtain( Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888), bitmapPool); } });
@Nullable static Resource<Bitmap> convert(BitmapPool bitmapPool, Drawable drawable, int width, int height) { // Handle DrawableContainer or StateListDrawables that may contain one or more BitmapDrawables. drawable = drawable.getCurrent(); Bitmap result = null; boolean isRecycleable = false; if (drawable instanceof BitmapDrawable) { result = ((BitmapDrawable) drawable).getBitmap(); } else if (!(drawable instanceof Animatable)) { result = drawToBitmap(bitmapPool, drawable, width, height); // We created and drew to the Bitmap, so it's safe for us to recycle or re-use. isRecycleable = true; } BitmapPool toUse = isRecycleable ? bitmapPool : NO_RECYCLE_BITMAP_POOL; return BitmapResource.obtain(result, toUse); }
/** * @deprecated Use {@link #obtain(Resources, Resource)} instead, it can be unsafe to extract * {@link Bitmap}s from their wrapped {@link Resource}. */ @Deprecated public static LazyBitmapDrawableResource obtain(Context context, Bitmap bitmap) { return (LazyBitmapDrawableResource) obtain( context.getResources(), BitmapResource.obtain(bitmap, Glide.get(context).getBitmapPool())); }
@Nullable @Override public Resource<byte[]> transcode(@NonNull Resource<Drawable> toTranscode, @NonNull Options options) { Drawable drawable = toTranscode.get(); if (drawable instanceof BitmapDrawable) { return bitmapBytesTranscoder.transcode( BitmapResource.obtain(((BitmapDrawable) drawable).getBitmap(), bitmapPool), options); } else if (drawable instanceof GifDrawable) { return gifDrawableBytesTranscoder.transcode(toGifDrawableResource(toTranscode), options); } return null; }
@NonNull @Override public final Resource<Bitmap> transform( @NonNull Context context, @NonNull Resource<Bitmap> resource, int outWidth, int outHeight) { if (!Util.isValidDimensions(outWidth, outHeight)) { throw new IllegalArgumentException( "Cannot apply transformation on width: " + outWidth + " or height: " + outHeight + " less than or equal to zero and not Target.SIZE_ORIGINAL"); } BitmapPool bitmapPool = Glide.get(context).getBitmapPool(); Bitmap toTransform = resource.get(); int targetWidth = outWidth == Target.SIZE_ORIGINAL ? toTransform.getWidth() : outWidth; int targetHeight = outHeight == Target.SIZE_ORIGINAL ? toTransform.getHeight() : outHeight; Bitmap transformed = transform(bitmapPool, toTransform, targetWidth, targetHeight); final Resource<Bitmap> result; if (toTransform.equals(transformed)) { result = resource; } else { result = BitmapResource.obtain(transformed, bitmapPool); } return result; }
@NonNull @Override public final Resource<Bitmap> transform(@NonNull Context context, @NonNull Resource<Bitmap> resource, int outWidth, int outHeight) { if (!Util.isValidDimensions(outWidth, outHeight)) { throw new IllegalArgumentException( "Cannot apply transformation on width: " + outWidth + " or height: " + outHeight + " less than or equal to zero and not Target.SIZE_ORIGINAL"); } BitmapPool bitmapPool = Glide.get(context).getBitmapPool(); Bitmap toTransform = resource.get(); int targetWidth = outWidth == Target.SIZE_ORIGINAL ? toTransform.getWidth() : outWidth; int targetHeight = outHeight == Target.SIZE_ORIGINAL ? toTransform.getHeight() : outHeight; Bitmap transformed = transform(context.getApplicationContext(), bitmapPool, toTransform, targetWidth, targetHeight); final Resource<Bitmap> result; if (toTransform.equals(transformed)) { result = resource; } else { result = BitmapResource.obtain(transformed, bitmapPool); } return result; }
return BitmapResource.obtain(result, bitmapPool);
memoryCache.put(uniqueKey, BitmapResource.obtain(bitmap, bitmapPool)); } else { bitmapPool.put(bitmap);
downsampleStrategy, decodeFormat, isHardwareConfigAllowed, requestedWidth, requestedHeight, fixBitmapToRequestedDimensions, callbacks); return BitmapResource.obtain(result, bitmapPool); } finally { releaseOptions(bitmapFactoryOptions);
@Override public Resource<Bitmap> decode(ParcelFileDescriptor source, int width, int height) throws IOException { Bitmap bitmap = bitmapDecoder.decode(source, bitmapPool, width, height, decodeFormat); return BitmapResource.obtain(bitmap, bitmapPool); }
@Override public Resource<Bitmap> decode(InputStream source, int width, int height) { Bitmap bitmap = downsampler.decode(source, bitmapPool, width, height, decodeFormat); return BitmapResource.obtain(bitmap, bitmapPool); }
@Override public Resource<Bitmap> decode(GifDecoder source, int width, int height) { Bitmap bitmap = source.getNextFrame(); return BitmapResource.obtain(bitmap, bitmapPool); }
@Override public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) { Bitmap source = resource.get(); int size = Math.min(source.getWidth(), source.getHeight()); mWidth = (source.getWidth() - size) / 2; mHeight = (source.getHeight() - size) / 2; Bitmap.Config config = source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888; Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config); if (bitmap == null) { bitmap = Bitmap.createBitmap(source, mWidth, mHeight, size, size); } return BitmapResource.obtain(bitmap, mBitmapPool); }
@Override public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) { Bitmap source = resource.get(); int width = source.getWidth(); int height = source.getHeight(); Bitmap result = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888); if (result == null) { result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); } Drawable mask = Utils.getMaskDrawable(mContext, mMaskId); Canvas canvas = new Canvas(result); mask.setBounds(0, 0, width, height); mask.draw(canvas); canvas.drawBitmap(source, 0, 0, sMaskingPaint); return BitmapResource.obtain(result, mBitmapPool); }
@Override public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) { Bitmap source = resource.get(); int width = source.getWidth(); int height = source.getHeight(); Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888); if (bitmap == null) { bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)); drawRoundRect(canvas, paint, width, height); return BitmapResource.obtain(bitmap, mBitmapPool); }
@Override public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) { Bitmap source = resource.get(); int width = source.getWidth(); int height = source.getHeight(); Bitmap.Config config = source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888; Bitmap bitmap = mBitmapPool.get(width, height, config); if (bitmap == null) { bitmap = Bitmap.createBitmap(width, height, config); } Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColorFilter(new PorterDuffColorFilter(mColor, PorterDuff.Mode.SRC_ATOP)); canvas.drawBitmap(source, 0, 0, paint); return BitmapResource.obtain(bitmap, mBitmapPool); }
@Override public final Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) { if (!Util.isValidDimensions(outWidth, outHeight)) { throw new IllegalArgumentException("Cannot apply transformation on width: " + outWidth + " or height: " + outHeight + " less than or equal to zero and not Target.SIZE_ORIGINAL"); } Bitmap toTransform = resource.get(); int targetWidth = outWidth == Target.SIZE_ORIGINAL ? toTransform.getWidth() : outWidth; int targetHeight = outHeight == Target.SIZE_ORIGINAL ? toTransform.getHeight() : outHeight; Bitmap transformed = transform(bitmapPool, toTransform, targetWidth, targetHeight); final Resource<Bitmap> result; if (toTransform.equals(transformed)) { result = resource; } else { result = BitmapResource.obtain(transformed, bitmapPool); } return result; }
@Override public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) { Bitmap source = resource.get(); int width = source.getWidth(); int height = source.getHeight(); Bitmap.Config config = source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888; Bitmap bitmap = mBitmapPool.get(width, height, config); if (bitmap == null) { bitmap = Bitmap.createBitmap(width, height, config); } Canvas canvas = new Canvas(bitmap); ColorMatrix saturation = new ColorMatrix(); saturation.setSaturation(0f); Paint paint = new Paint(); paint.setColorFilter(new ColorMatrixColorFilter(saturation)); canvas.drawBitmap(source, 0, 0, paint); return BitmapResource.obtain(bitmap, mBitmapPool); }