Search in sources :

Example 1 with BitmapPool

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);
    }
}
Also used : GifDrawableTransformation(com.bumptech.glide.load.resource.gif.GifDrawableTransformation) BitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool)

Example 2 with BitmapPool

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());
    }
}
Also used : Bitmap(android.graphics.Bitmap) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool)

Example 3 with BitmapPool

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));
}
Also used : Context(android.content.Context) Config(org.robolectric.annotation.Config) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool) Bitmap(android.graphics.Bitmap) ColorDrawable(android.graphics.drawable.ColorDrawable) InvocationOnMock(org.mockito.invocation.InvocationOnMock) GlideBuilder(com.bumptech.glide.GlideBuilder) SimpleResource(com.bumptech.glide.load.resource.SimpleResource) Test(org.junit.Test)

Example 4 with BitmapPool

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);
    }
}
Also used : Bitmap(android.graphics.Bitmap) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) BitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool) NonNull(android.support.annotation.NonNull)

Example 5 with BitmapPool

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;
}
Also used : Bitmap(android.graphics.Bitmap) BitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool) NonNull(android.support.annotation.NonNull)

Aggregations

BitmapPool (com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool)17 Bitmap (android.graphics.Bitmap)15 BitmapDrawable (android.graphics.drawable.BitmapDrawable)7 Test (org.junit.Test)6 Drawable (android.graphics.drawable.Drawable)5 ColorDrawable (android.graphics.drawable.ColorDrawable)4 NonNull (android.support.annotation.NonNull)4 GlideBuilder (com.bumptech.glide.GlideBuilder)3 BitmapPoolAdapter (com.bumptech.glide.load.engine.bitmap_recycle.BitmapPoolAdapter)3 Before (org.junit.Before)2 Context (android.content.Context)1 Canvas (android.graphics.Canvas)1 Animatable (android.graphics.drawable.Animatable)1 Nullable (android.support.annotation.Nullable)1 DisplayMetrics (android.util.DisplayMetrics)1 NonNull (androidx.annotation.NonNull)1 ImageHeaderParser (com.bumptech.glide.load.ImageHeaderParser)1 ArrayPool (com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool)1 LruArrayPool (com.bumptech.glide.load.engine.bitmap_recycle.LruArrayPool)1 LruBitmapPool (com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool)1