Search in sources :

Example 1 with BitmapResource

use of com.bumptech.glide.load.resource.bitmap.BitmapResource in project glide by bumptech.

the class GifDrawableTransformation method transform.

@Override
public Resource<GifDrawable> transform(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.
    Bitmap firstFrame = drawable.getFirstFrame();
    Resource<Bitmap> bitmapResource = new BitmapResource(firstFrame, bitmapPool);
    Resource<Bitmap> transformed = wrapped.transform(bitmapResource, outWidth, outHeight);
    if (!bitmapResource.equals(transformed)) {
        bitmapResource.recycle();
    }
    Bitmap transformedFrame = transformed.get();
    drawable.setFrameTransformation(wrapped, transformedFrame);
    return resource;
}
Also used : Bitmap(android.graphics.Bitmap) BitmapResource(com.bumptech.glide.load.resource.bitmap.BitmapResource)

Example 2 with BitmapResource

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

Aggregations

Bitmap (android.graphics.Bitmap)2 BitmapResource (com.bumptech.glide.load.resource.bitmap.BitmapResource)2 NonNull (android.support.annotation.NonNull)1 BitmapPool (com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool)1