Search in sources :

Example 1 with AnimatedGifEncoder

use of com.bumptech.glide.gifencoder.AnimatedGifEncoder in project glide by bumptech.

the class ReEncodingGifResourceEncoder method encodeTransformedToStream.

private boolean encodeTransformedToStream(GifDrawable drawable, OutputStream os) {
    Transformation<Bitmap> transformation = drawable.getFrameTransformation();
    GifDecoder decoder = decodeHeaders(drawable.getBuffer());
    AnimatedGifEncoder encoder = factory.buildEncoder();
    if (!encoder.start(os)) {
        return false;
    }
    for (int i = 0; i < decoder.getFrameCount(); i++) {
        Bitmap currentFrame = decoder.getNextFrame();
        Resource<Bitmap> transformedResource = getTransformedFrame(currentFrame, transformation, drawable);
        try {
            if (!encoder.addFrame(transformedResource.get())) {
                return false;
            }
            int currentFrameIndex = decoder.getCurrentFrameIndex();
            int delay = decoder.getDelay(currentFrameIndex);
            encoder.setDelay(delay);
            decoder.advance();
        } finally {
            transformedResource.recycle();
        }
    }
    return encoder.finish();
}
Also used : GifDecoder(com.bumptech.glide.gifdecoder.GifDecoder) StandardGifDecoder(com.bumptech.glide.gifdecoder.StandardGifDecoder) Bitmap(android.graphics.Bitmap) AnimatedGifEncoder(com.bumptech.glide.gifencoder.AnimatedGifEncoder)

Aggregations

Bitmap (android.graphics.Bitmap)1 GifDecoder (com.bumptech.glide.gifdecoder.GifDecoder)1 StandardGifDecoder (com.bumptech.glide.gifdecoder.StandardGifDecoder)1 AnimatedGifEncoder (com.bumptech.glide.gifencoder.AnimatedGifEncoder)1