use of com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool in project WeexErosFramework by bmfe.
the class DefaultWXImageAdapter method showAndCropGif.
private void showAndCropGif(String url, WXImageView view, WXImageStrategy mStrategy) {
BMRadiusTransfer radiusTransfer = new BMRadiusTransfer(WXEnvironment.getApplication(), view);
BitmapPool bitmapPool = Glide.get(WXEnvironment.getApplication()).getBitmapPool();
BMHookGlide.load(WXEnvironment.getApplication(), url).asGif().transform(new GifDrawableTransformation(radiusTransfer, bitmapPool)).into(view);
if (mStrategy != null && mStrategy.getImageListener() != null) {
mStrategy.getImageListener().onImageFinish(url, view, true, null);
}
}
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 DrawableTransformationTest method transform_withColorDrawable_andUnitBitmapTransformation_recycles.
@Test
public void transform_withColorDrawable_andUnitBitmapTransformation_recycles() {
bitmapPool = mock(BitmapPool.class);
Glide.tearDown();
Glide.init(context, new GlideBuilder().setBitmapPool(bitmapPool));
when(bitmapTransformation.transform(any(Context.class), anyBitmapResource(), anyInt(), anyInt())).thenAnswer(new ReturnGivenResource());
ColorDrawable colorDrawable = new ColorDrawable(Color.RED);
final Resource<Drawable> input = new SimpleResource<Drawable>(colorDrawable);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
Bitmap bitmap = (Bitmap) invocationOnMock.getArguments()[0];
assertThat(bitmap.getWidth()).isEqualTo(100);
assertThat(bitmap.getHeight()).isEqualTo(200);
return null;
}
}).when(bitmapPool).put(any(Bitmap.class));
when(bitmapPool.get(anyInt(), anyInt(), any(Bitmap.Config.class))).thenAnswer(new Answer<Bitmap>() {
@Override
public Bitmap answer(InvocationOnMock invocationOnMock) throws Throwable {
int width = (Integer) invocationOnMock.getArguments()[0];
int height = (Integer) invocationOnMock.getArguments()[1];
Bitmap.Config config = (Bitmap.Config) invocationOnMock.getArguments()[2];
return Bitmap.createBitmap(width, height, config);
}
});
transformation.transform(context, input, /*outWidth=*/
100, /*outHeight=*/
200);
verify(bitmapPool).put(isA(Bitmap.class));
}
use of com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool in project glide by bumptech.
the class DrawableTransformation method transform.
@NonNull
@Override
public Resource<Drawable> transform(@NonNull Context context, @NonNull Resource<Drawable> resource, int outWidth, int outHeight) {
BitmapPool bitmapPool = Glide.get(context).getBitmapPool();
Drawable drawable = resource.get();
Resource<Bitmap> bitmapResourceToTransform = DrawableToBitmapConverter.convert(bitmapPool, drawable, outWidth, outHeight);
if (bitmapResourceToTransform == null) {
if (isRequired) {
throw new IllegalArgumentException("Unable to convert " + drawable + " to a Bitmap");
} else {
return resource;
}
}
Resource<Bitmap> transformedBitmapResource = wrapped.transform(context, bitmapResourceToTransform, outWidth, outHeight);
if (transformedBitmapResource.equals(bitmapResourceToTransform)) {
transformedBitmapResource.recycle();
return resource;
} else {
return newDrawableResource(context, transformedBitmapResource);
}
}
use of com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool in project glide by bumptech.
the class BitmapTransformation method transform.
@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;
}
Aggregations