Search in sources :

Example 6 with AnimatedImageCompositor

use of com.facebook.imagepipeline.animated.impl.AnimatedImageCompositor in project fresco by facebook.

the class AnimatedImageFactoryImpl method decodeAllFrames.

private List<CloseableReference<Bitmap>> decodeAllFrames(AnimatedImage image, Bitmap.Config bitmapConfig) {
    AnimatedImageResult tempResult = AnimatedImageResult.forAnimatedImage(image);
    AnimatedDrawableBackend drawableBackend = mAnimatedDrawableBackendProvider.get(tempResult, null);
    final List<CloseableReference<Bitmap>> bitmaps = new ArrayList<>(drawableBackend.getFrameCount());
    AnimatedImageCompositor animatedImageCompositor = new AnimatedImageCompositor(drawableBackend, new AnimatedImageCompositor.Callback() {

        @Override
        public void onIntermediateResult(int frameNumber, Bitmap bitmap) {
        // Don't care.
        }

        @Override
        public CloseableReference<Bitmap> getCachedBitmap(int frameNumber) {
            return CloseableReference.cloneOrNull(bitmaps.get(frameNumber));
        }
    });
    for (int i = 0; i < drawableBackend.getFrameCount(); i++) {
        CloseableReference<Bitmap> bitmap = createBitmap(drawableBackend.getWidth(), drawableBackend.getHeight(), bitmapConfig);
        animatedImageCompositor.renderFrame(i, bitmap.get());
        bitmaps.add(bitmap);
    }
    return bitmaps;
}
Also used : AnimatedDrawableBackend(com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend) Bitmap(android.graphics.Bitmap) CloseableStaticBitmap(com.facebook.imagepipeline.image.CloseableStaticBitmap) AnimatedImageResult(com.facebook.imagepipeline.animated.base.AnimatedImageResult) ArrayList(java.util.ArrayList) CloseableReference(com.facebook.common.references.CloseableReference) AnimatedImageCompositor(com.facebook.imagepipeline.animated.impl.AnimatedImageCompositor) SuppressLint(android.annotation.SuppressLint)

Example 7 with AnimatedImageCompositor

use of com.facebook.imagepipeline.animated.impl.AnimatedImageCompositor in project fresco by facebook.

the class AnimatedImageFactoryImpl method createPreviewBitmap.

private CloseableReference<Bitmap> createPreviewBitmap(AnimatedImage image, Bitmap.Config bitmapConfig, int frameForPreview) {
    CloseableReference<Bitmap> bitmap = createBitmap(image.getWidth(), image.getHeight(), bitmapConfig);
    AnimatedImageResult tempResult = AnimatedImageResult.forAnimatedImage(image);
    AnimatedDrawableBackend drawableBackend = mAnimatedDrawableBackendProvider.get(tempResult, null);
    AnimatedImageCompositor animatedImageCompositor = new AnimatedImageCompositor(drawableBackend, new AnimatedImageCompositor.Callback() {

        @Override
        public void onIntermediateResult(int frameNumber, Bitmap bitmap) {
        // Don't care.
        }

        @Override
        public CloseableReference<Bitmap> getCachedBitmap(int frameNumber) {
            return null;
        }
    });
    animatedImageCompositor.renderFrame(frameForPreview, bitmap.get());
    return bitmap;
}
Also used : AnimatedDrawableBackend(com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend) Bitmap(android.graphics.Bitmap) CloseableStaticBitmap(com.facebook.imagepipeline.image.CloseableStaticBitmap) AnimatedImageResult(com.facebook.imagepipeline.animated.base.AnimatedImageResult) CloseableReference(com.facebook.common.references.CloseableReference) AnimatedImageCompositor(com.facebook.imagepipeline.animated.impl.AnimatedImageCompositor) SuppressLint(android.annotation.SuppressLint)

Aggregations

AnimatedDrawableBackend (com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend)7 AnimatedImageCompositor (com.facebook.imagepipeline.animated.impl.AnimatedImageCompositor)7 Bitmap (android.graphics.Bitmap)6 AnimatedImageResult (com.facebook.imagepipeline.animated.base.AnimatedImageResult)6 Rect (android.graphics.Rect)4 ImageDecodeOptions (com.facebook.imagepipeline.common.ImageDecodeOptions)4 CloseableAnimatedImage (com.facebook.imagepipeline.image.CloseableAnimatedImage)4 EncodedImage (com.facebook.imagepipeline.image.EncodedImage)4 TrivialPooledByteBuffer (com.facebook.imagepipeline.testing.TrivialPooledByteBuffer)4 Test (org.junit.Test)4 PrepareOnlyThisForTest (org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)4 SuppressLint (android.annotation.SuppressLint)2 GifImage (com.facebook.animated.gif.GifImage)2 WebPImage (com.facebook.animated.webp.WebPImage)2 CloseableReference (com.facebook.common.references.CloseableReference)2 CloseableStaticBitmap (com.facebook.imagepipeline.image.CloseableStaticBitmap)2 ArrayList (java.util.ArrayList)1