Search in sources :

Example 36 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project DevRing by LJYcoder.

the class FrescoManager method preLoad.

@Override
public void preLoad(String url) {
    ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(Preconditions.checkNotNull(url, "预加载的图片路径不能为空"))).build();
    Fresco.getImagePipeline().prefetchToBitmapCache(imageRequest, null);
    Fresco.getImagePipeline().prefetchToDiskCache(imageRequest, null);
}
Also used : ImageRequest(com.facebook.imagepipeline.request.ImageRequest)

Example 37 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project DevRing by LJYcoder.

the class FrescoManager method getBitmap.

@Override
public void getBitmap(Context context, String url, final ImageListener<Bitmap> imageListener) {
    // 参考自https://github.com/hpdx/fresco-helper/blob/master/fresco-helper/src/main/java/com/facebook/fresco/helper/ImageLoader.java
    Uri uri = Uri.parse(url);
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(uri);
    ImageRequest imageRequest = builder.build();
    DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);
    dataSource.subscribe(new BaseDataSubscriber<CloseableReference<CloseableImage>>() {

        @Override
        public void onNewResultImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
            if (!dataSource.isFinished()) {
                return;
            }
            CloseableReference<CloseableImage> imageReference = dataSource.getResult();
            if (imageReference != null) {
                final CloseableReference<CloseableImage> closeableReference = imageReference.clone();
                try {
                    CloseableImage closeableImage = closeableReference.get();
                    // 动图处理
                    if (closeableImage instanceof CloseableAnimatedImage) {
                        AnimatedImageResult animatedImageResult = ((CloseableAnimatedImage) closeableImage).getImageResult();
                        if (animatedImageResult != null && animatedImageResult.getImage() != null) {
                            int imageWidth = animatedImageResult.getImage().getWidth();
                            int imageHeight = animatedImageResult.getImage().getHeight();
                            Bitmap.Config bitmapConfig = Bitmap.Config.ARGB_8888;
                            Bitmap bitmap = Bitmap.createBitmap(imageWidth, imageHeight, bitmapConfig);
                            animatedImageResult.getImage().getFrame(0).renderFrame(imageWidth, imageHeight, bitmap);
                            if (imageListener != null) {
                                imageListener.onSuccess(bitmap);
                            }
                        }
                    } else // 非动图处理
                    if (closeableImage instanceof CloseableBitmap) {
                        CloseableBitmap closeableBitmap = (CloseableBitmap) closeableImage;
                        Bitmap bitmap = closeableBitmap.getUnderlyingBitmap();
                        if (bitmap != null && !bitmap.isRecycled()) {
                            // https://github.com/facebook/fresco/issues/648
                            final Bitmap tempBitmap = bitmap.copy(bitmap.getConfig(), false);
                            if (imageListener != null) {
                                imageListener.onSuccess(tempBitmap);
                            }
                        }
                    }
                } finally {
                    imageReference.close();
                    closeableReference.close();
                }
            }
        }

        @Override
        public void onFailureImpl(DataSource dataSource) {
            Throwable throwable = dataSource.getFailureCause();
            if (imageListener != null) {
                imageListener.onFail(throwable);
            }
        }
    }, UiThreadImmediateExecutorService.getInstance());
}
Also used : CloseableAnimatedImage(com.facebook.imagepipeline.image.CloseableAnimatedImage) DiskCacheConfig(com.facebook.cache.disk.DiskCacheConfig) ImageConfig(com.ljy.devring.image.support.ImageConfig) ImagePipelineConfig(com.facebook.imagepipeline.core.ImagePipelineConfig) SimpleProgressiveJpegConfig(com.facebook.imagepipeline.decoder.SimpleProgressiveJpegConfig) CloseableReference(com.facebook.common.references.CloseableReference) AnimatedImageResult(com.facebook.imagepipeline.animated.base.AnimatedImageResult) CloseableImage(com.facebook.imagepipeline.image.CloseableImage) Uri(android.net.Uri) CloseableBitmap(com.facebook.imagepipeline.image.CloseableBitmap) DataSource(com.facebook.datasource.DataSource) CloseableBitmap(com.facebook.imagepipeline.image.CloseableBitmap) Bitmap(android.graphics.Bitmap) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) ImagePipeline(com.facebook.imagepipeline.core.ImagePipeline) ImageRequestBuilder(com.facebook.imagepipeline.request.ImageRequestBuilder)

Example 38 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project DevRing by LJYcoder.

the class FrescoManager method load.

private void load(Uri uri, ImageView imageView, LoadOption loadOption) {
    Preconditions.checkNotNull(imageView, "加载图片的控件不能为空!");
    if (imageView instanceof SimpleDraweeView) {
        SimpleDraweeView simpleDraweeView = (SimpleDraweeView) imageView;
        setHierarchay(simpleDraweeView.getHierarchy(), loadOption);
        ImageRequest imageRequest = getImageRequest(uri, simpleDraweeView, loadOption);
        DraweeController draweeController = getController(imageRequest, simpleDraweeView.getController());
        simpleDraweeView.setController(draweeController);
    } else {
        throw new IllegalArgumentException("Fresco加载图片的控件需为SimpleDraweeView");
    }
}
Also used : SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) DraweeController(com.facebook.drawee.interfaces.DraweeController) ImageRequest(com.facebook.imagepipeline.request.ImageRequest)

Example 39 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project MyDiary by erttyy8821.

the class DiaryPhotoLayout method setPhotoUri.

public void setPhotoUri(Uri photoUri) {
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(photoUri).setResizeOptions(new ResizeOptions(DiaryItemHelper.getVisibleWidth(getContext()), DiaryItemHelper.getVisibleHeight(getContext()))).setRotationOptions(RotationOptions.autoRotate()).build();
    DraweeController controller = Fresco.newDraweeControllerBuilder().setImageRequest(request).build();
    SDV_diary_new_photo.setController(controller);
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) DraweeController(com.facebook.drawee.interfaces.DraweeController) ImageRequest(com.facebook.imagepipeline.request.ImageRequest)

Example 40 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project fresco by facebook.

the class PipelineDraweeControllerBuilder method getCacheKey.

private CacheKey getCacheKey() {
    final ImageRequest imageRequest = getImageRequest();
    final CacheKeyFactory cacheKeyFactory = mImagePipeline.getCacheKeyFactory();
    CacheKey cacheKey = null;
    if (cacheKeyFactory != null && imageRequest != null) {
        if (imageRequest.getPostprocessor() != null) {
            cacheKey = cacheKeyFactory.getPostprocessedBitmapCacheKey(imageRequest, getCallerContext());
        } else {
            cacheKey = cacheKeyFactory.getBitmapCacheKey(imageRequest, getCallerContext());
        }
    }
    return cacheKey;
}
Also used : CacheKeyFactory(com.facebook.imagepipeline.cache.CacheKeyFactory) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) CacheKey(com.facebook.cache.common.CacheKey)

Aggregations

ImageRequest (com.facebook.imagepipeline.request.ImageRequest)71 DraweeController (com.facebook.drawee.interfaces.DraweeController)22 ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)19 CloseableReference (com.facebook.common.references.CloseableReference)17 Uri (android.net.Uri)13 Bitmap (android.graphics.Bitmap)11 ImagePipeline (com.facebook.imagepipeline.core.ImagePipeline)11 File (java.io.File)10 CacheKey (com.facebook.cache.common.CacheKey)9 DataSource (com.facebook.datasource.DataSource)8 BaseBitmapDataSubscriber (com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber)8 PipelineDraweeController (com.facebook.drawee.backends.pipeline.PipelineDraweeController)7 Animatable (android.graphics.drawable.Animatable)6 BaseControllerListener (com.facebook.drawee.controller.BaseControllerListener)6 CloseableImage (com.facebook.imagepipeline.image.CloseableImage)6 ImageInfo (com.facebook.imagepipeline.image.ImageInfo)6 EncodedImage (com.facebook.imagepipeline.image.EncodedImage)5 ImageRequestBuilder (com.facebook.imagepipeline.request.ImageRequestBuilder)5 Nullable (android.support.annotation.Nullable)4 FileBinaryResource (com.facebook.binaryresource.FileBinaryResource)4