Search in sources :

Example 1 with CloseableStaticBitmap

use of com.facebook.imagepipeline.image.CloseableStaticBitmap in project fresco by facebook.

the class AnimatedImageFactoryImpl method getCloseableImage.

private CloseableImage getCloseableImage(ImageDecodeOptions options, AnimatedImage image, Bitmap.Config bitmapConfig) {
    List<CloseableReference<Bitmap>> decodedFrames = null;
    CloseableReference<Bitmap> previewBitmap = null;
    try {
        final int frameForPreview = options.useLastFrameForPreview ? image.getFrameCount() - 1 : 0;
        if (options.forceStaticImage) {
            return new CloseableStaticBitmap(createPreviewBitmap(image, bitmapConfig, frameForPreview), ImmutableQualityInfo.FULL_QUALITY, 0);
        }
        if (options.decodeAllFrames) {
            decodedFrames = decodeAllFrames(image, bitmapConfig);
            previewBitmap = CloseableReference.cloneOrNull(decodedFrames.get(frameForPreview));
        }
        if (options.decodePreviewFrame && previewBitmap == null) {
            previewBitmap = createPreviewBitmap(image, bitmapConfig, frameForPreview);
        }
        AnimatedImageResult animatedImageResult = AnimatedImageResult.newBuilder(image).setPreviewBitmap(previewBitmap).setFrameForPreview(frameForPreview).setDecodedFrames(decodedFrames).build();
        return new CloseableAnimatedImage(animatedImageResult);
    } finally {
        CloseableReference.closeSafely(previewBitmap);
        CloseableReference.closeSafely(decodedFrames);
    }
}
Also used : Bitmap(android.graphics.Bitmap) CloseableStaticBitmap(com.facebook.imagepipeline.image.CloseableStaticBitmap) CloseableAnimatedImage(com.facebook.imagepipeline.image.CloseableAnimatedImage) CloseableReference(com.facebook.common.references.CloseableReference) AnimatedImageResult(com.facebook.imagepipeline.animated.base.AnimatedImageResult) CloseableStaticBitmap(com.facebook.imagepipeline.image.CloseableStaticBitmap) SuppressLint(android.annotation.SuppressLint)

Example 2 with CloseableStaticBitmap

use of com.facebook.imagepipeline.image.CloseableStaticBitmap in project boxing by Bilibili.

the class BoxingFrescoLoader method createDrawableFromFetchedResult.

private Drawable createDrawableFromFetchedResult(Context context, CloseableImage image) {
    if (image instanceof CloseableStaticBitmap) {
        CloseableStaticBitmap closeableStaticBitmap = (CloseableStaticBitmap) image;
        BitmapDrawable bitmapDrawable = createBitmapDrawable(context, closeableStaticBitmap.getUnderlyingBitmap());
        return (closeableStaticBitmap.getRotationAngle() != 0 && closeableStaticBitmap.getRotationAngle() != -1 ? new OrientedDrawable(bitmapDrawable, closeableStaticBitmap.getRotationAngle()) : bitmapDrawable);
    } else if (image instanceof CloseableAnimatedImage) {
        AnimatedDrawableFactory animatedDrawableFactory = Fresco.getImagePipelineFactory().getAnimatedFactory().getAnimatedDrawableFactory(context);
        if (animatedDrawableFactory != null) {
            AnimatedDrawable animatedDrawable = (AnimatedDrawable) animatedDrawableFactory.create(image);
            if (animatedDrawable != null) {
                return animatedDrawable;
            }
        }
    }
    throw new UnsupportedOperationException("Unrecognized image class: " + image);
}
Also used : OrientedDrawable(com.facebook.drawee.drawable.OrientedDrawable) CloseableAnimatedImage(com.facebook.imagepipeline.image.CloseableAnimatedImage) AnimatedDrawableFactory(com.facebook.imagepipeline.animated.factory.AnimatedDrawableFactory) CloseableStaticBitmap(com.facebook.imagepipeline.image.CloseableStaticBitmap) BitmapDrawable(android.graphics.drawable.BitmapDrawable) AnimatedDrawable(com.facebook.imagepipeline.animated.base.AnimatedDrawable)

Example 3 with CloseableStaticBitmap

use of com.facebook.imagepipeline.image.CloseableStaticBitmap in project fresco by facebook.

the class FrescoFrameCache method onFrameRendered.

@Override
public synchronized void onFrameRendered(int frameNumber, CloseableReference<Bitmap> bitmapReference, @BitmapAnimationBackend.FrameType int frameType) {
    Preconditions.checkNotNull(bitmapReference);
    CloseableReference<CloseableImage> closableReference = null;
    try {
        // The given CloseableStaticBitmap will be cached and then released by the resource releaser
        // of the closeable reference
        CloseableImage closeableImage = new CloseableStaticBitmap(bitmapReference, ImmutableQualityInfo.FULL_QUALITY, 0);
        closableReference = CloseableReference.of(closeableImage);
        CloseableReference.closeSafely(mLastCachedItem);
        mLastCachedItem = mAnimatedFrameCache.cache(frameNumber, closableReference);
    } finally {
        CloseableReference.closeSafely(closableReference);
    }
}
Also used : CloseableImage(com.facebook.imagepipeline.image.CloseableImage) CloseableStaticBitmap(com.facebook.imagepipeline.image.CloseableStaticBitmap)

Example 4 with CloseableStaticBitmap

use of com.facebook.imagepipeline.image.CloseableStaticBitmap in project fresco by facebook.

the class LocalVideoThumbnailProducer method produceResults.

@Override
public void produceResults(final Consumer<CloseableReference<CloseableImage>> consumer, final ProducerContext producerContext) {
    final ProducerListener listener = producerContext.getListener();
    final String requestId = producerContext.getId();
    final ImageRequest imageRequest = producerContext.getImageRequest();
    final StatefulProducerRunnable cancellableProducerRunnable = new StatefulProducerRunnable<CloseableReference<CloseableImage>>(consumer, listener, PRODUCER_NAME, requestId) {

        @Override
        protected CloseableReference<CloseableImage> getResult() throws Exception {
            Bitmap thumbnailBitmap = ThumbnailUtils.createVideoThumbnail(imageRequest.getSourceFile().getPath(), calculateKind(imageRequest));
            if (thumbnailBitmap == null) {
                return null;
            }
            return CloseableReference.<CloseableImage>of(new CloseableStaticBitmap(thumbnailBitmap, SimpleBitmapReleaser.getInstance(), ImmutableQualityInfo.FULL_QUALITY, 0));
        }

        @Override
        protected Map<String, String> getExtraMapOnSuccess(final CloseableReference<CloseableImage> result) {
            return ImmutableMap.of(CREATED_THUMBNAIL, String.valueOf(result != null));
        }

        @Override
        protected void disposeResult(CloseableReference<CloseableImage> result) {
            CloseableReference.closeSafely(result);
        }
    };
    producerContext.addCallbacks(new BaseProducerContextCallbacks() {

        @Override
        public void onCancellationRequested() {
            cancellableProducerRunnable.cancel();
        }
    });
    mExecutor.execute(cancellableProducerRunnable);
}
Also used : Bitmap(android.graphics.Bitmap) CloseableStaticBitmap(com.facebook.imagepipeline.image.CloseableStaticBitmap) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) CloseableReference(com.facebook.common.references.CloseableReference) CloseableImage(com.facebook.imagepipeline.image.CloseableImage) CloseableStaticBitmap(com.facebook.imagepipeline.image.CloseableStaticBitmap)

Example 5 with CloseableStaticBitmap

use of com.facebook.imagepipeline.image.CloseableStaticBitmap in project boxing by Bilibili.

the class BoxingFrescoLoader method displayThumbnail.

@Override
public void displayThumbnail(@NonNull final ImageView img, @NonNull final String absPath, int width, int height) {
    String finalAbsPath = "file://" + absPath;
    ImageRequestBuilder requestBuilder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(finalAbsPath));
    requestBuilder.setResizeOptions(new ResizeOptions(width, height));
    ImageRequest request = requestBuilder.build();
    final DataSource<CloseableReference<CloseableImage>> dataSource = Fresco.getImagePipeline().fetchDecodedImage(request, null);
    dataSource.subscribe(new BaseDataSubscriber<CloseableReference<CloseableImage>>() {

        @Override
        protected void onNewResultImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
            String path = (String) img.getTag(R.string.app_name);
            if (path == null || absPath.equals(path)) {
                if (dataSource.getResult() == null) {
                    onFailureImpl(dataSource);
                    return;
                }
                CloseableStaticBitmap bitmap = (CloseableStaticBitmap) dataSource.getResult().get();
                img.setImageBitmap(bitmap.getUnderlyingBitmap());
            }
        }

        @Override
        protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
            img.setImageResource(R.drawable.ic_default_image);
        }
    }, UiThreadImmediateExecutorService.getInstance());
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) CloseableReference(com.facebook.common.references.CloseableReference) CloseableStaticBitmap(com.facebook.imagepipeline.image.CloseableStaticBitmap) ImageRequestBuilder(com.facebook.imagepipeline.request.ImageRequestBuilder)

Aggregations

CloseableStaticBitmap (com.facebook.imagepipeline.image.CloseableStaticBitmap)5 CloseableReference (com.facebook.common.references.CloseableReference)3 Bitmap (android.graphics.Bitmap)2 CloseableAnimatedImage (com.facebook.imagepipeline.image.CloseableAnimatedImage)2 CloseableImage (com.facebook.imagepipeline.image.CloseableImage)2 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)2 SuppressLint (android.annotation.SuppressLint)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 OrientedDrawable (com.facebook.drawee.drawable.OrientedDrawable)1 AnimatedDrawable (com.facebook.imagepipeline.animated.base.AnimatedDrawable)1 AnimatedImageResult (com.facebook.imagepipeline.animated.base.AnimatedImageResult)1 AnimatedDrawableFactory (com.facebook.imagepipeline.animated.factory.AnimatedDrawableFactory)1 ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)1 ImageRequestBuilder (com.facebook.imagepipeline.request.ImageRequestBuilder)1