use of com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool in project glide by bumptech.
the class FitCenterTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
bitmapWidth = 100;
bitmapHeight = 100;
Bitmap bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
when(resource.get()).thenReturn(bitmap);
BitmapPool pool = new BitmapPoolAdapter();
context = RuntimeEnvironment.application;
Glide.init(context, new GlideBuilder().setBitmapPool(pool));
fitCenter = new FitCenter();
}
use of com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool in project Rocket by mozilla-tw.
the class BitmapDrawableTransformation method transform.
@Override
public Resource<BitmapDrawable> transform(Context context, Resource<BitmapDrawable> drawableResourceToTransform, int outWidth, int outHeight) {
BitmapDrawable drawableToTransform = drawableResourceToTransform.get();
Bitmap bitmapToTransform = drawableToTransform.getBitmap();
BitmapPool bitmapPool = Glide.get(context).getBitmapPool();
BitmapResource bitmapResourceToTransform = BitmapResource.obtain(bitmapToTransform, bitmapPool);
Resource<Bitmap> transformedBitmapResource = wrapped.transform(context, bitmapResourceToTransform, outWidth, outHeight);
if (transformedBitmapResource.equals(bitmapResourceToTransform)) {
return drawableResourceToTransform;
} else {
return LazyBitmapDrawableResource.obtain(context, transformedBitmapResource.get());
}
}
use of com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool in project glide by bumptech.
the class DrawableToBitmapConverter method convert.
@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);
}
use of com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool in project glide by bumptech.
the class GifDrawableTransformation method transform.
@NonNull
@Override
public Resource<GifDrawable> transform(@NonNull Context context, @NonNull Resource<GifDrawable> resource, int outWidth, int outHeight) {
GifDrawable drawable = resource.get();
// The drawable needs to be initialized with the correct width and height in order for a view
// displaying it to end up with the right dimensions. Since our transformations may arbitrarily
// modify the dimensions of our GIF, here we create a stand in for a frame and pass it to the
// transformation to see what the final transformed dimensions will be so that our drawable can
// report the correct intrinsic width and height.
BitmapPool bitmapPool = Glide.get(context).getBitmapPool();
Bitmap firstFrame = drawable.getFirstFrame();
Resource<Bitmap> bitmapResource = new BitmapResource(firstFrame, bitmapPool);
Resource<Bitmap> transformed = wrapped.transform(context, bitmapResource, outWidth, outHeight);
if (!bitmapResource.equals(transformed)) {
bitmapResource.recycle();
}
Bitmap transformedFrame = transformed.get();
drawable.setFrameTransformation(wrapped, transformedFrame);
return resource;
}
use of com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool in project glide by bumptech.
the class DrawableTransformationTest method load_withColorDrawable_fixedSize_unitBitmapTransform_recyclesIntermediates.
@Test
public void load_withColorDrawable_fixedSize_unitBitmapTransform_recyclesIntermediates() throws ExecutionException, InterruptedException {
Drawable colorDrawable = new ColorDrawable(Color.RED);
int width = 100;
int height = 200;
GlideApp.with(context).load(colorDrawable).fitCenter().override(width, height).submit().get();
BitmapPool bitmapPool = Glide.get(context).getBitmapPool();
// Make sure we didn't put the same Bitmap twice.
Bitmap first = bitmapPool.get(width, height, Config.ARGB_8888);
Bitmap second = bitmapPool.get(width, height, Config.ARGB_8888);
assertThat(first).isNotSameAs(second);
}
Aggregations