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();
}
Aggregations