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