Search in sources :

Example 11 with ImagePipeline

use of com.facebook.imagepipeline.core.ImagePipeline in project BigImageViewer by Piasy.

the class FrescoImageLoader method prefetch.

@Override
public void prefetch(Uri uri) {
    ImagePipeline pipeline = Fresco.getImagePipeline();
    pipeline.prefetchToDiskCache(ImageRequest.fromUri(uri), // we don't need context, but avoid null
    false);
}
Also used : ImagePipeline(com.facebook.imagepipeline.core.ImagePipeline)

Example 12 with ImagePipeline

use of com.facebook.imagepipeline.core.ImagePipeline in project ride-read-android by Ride-Read.

the class PersonalityMapActivity method addMoment2Map.

private void addMoment2Map(Moment moment) {
    LatLng latLng = new LatLng(moment.getLatitude(), moment.getLongitude());
    ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(moment.getPictures().get(0) + QiNiuUtils.CROP_SMALL_100)).setProgressiveRenderingEnabled(true).build();
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, Utils.getAppContext());
    dataSource.subscribe(new BaseBitmapDataSubscriber() {

        @Override
        public void onNewResultImpl(@Nullable Bitmap bitmap) {
            addMarker(latLng, bitmap, moment);
        }

        @Override
        public void onFailureImpl(DataSource dataSource) {
        }
    }, CallerThreadExecutor.getInstance());
}
Also used : Bitmap(android.graphics.Bitmap) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) CloseableReference(com.facebook.common.references.CloseableReference) LatLng(com.amap.api.maps.model.LatLng) ImagePipeline(com.facebook.imagepipeline.core.ImagePipeline) BaseBitmapDataSubscriber(com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber) DataSource(com.facebook.datasource.DataSource)

Example 13 with ImagePipeline

use of com.facebook.imagepipeline.core.ImagePipeline 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 14 with ImagePipeline

use of com.facebook.imagepipeline.core.ImagePipeline in project apps-android-wikipedia by wikimedia.

the class ImagePipelineBitmapGetter method get.

public void get() {
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(imageUrl)).build();
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(request, WikipediaApp.getInstance());
    dataSource.subscribe(new BitmapDataSubscriber(), UiThreadImmediateExecutorService.getInstance());
}
Also used : BaseBitmapDataSubscriber(com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) CloseableReference(com.facebook.common.references.CloseableReference) ImagePipeline(com.facebook.imagepipeline.core.ImagePipeline)

Example 15 with ImagePipeline

use of com.facebook.imagepipeline.core.ImagePipeline in project lzc_app_lib by httplzc.

the class BigImgDataRequestHelper method getHolderData.

// 获取holder 的catch
private void getHolderData(final WrapperUri wrapperUri) {
    final Uri holderUri = wrapperUri.getLowUri();
    if (holderUri == null)
        return;
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(holderUri).setResizeOptions(new ResizeOptions(ScreenData.widthPX / 3, ScreenData.heightPX / 3)).build();
    DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(request, "");
    dataSource.subscribe(new BaseDataSubscriber<CloseableReference<CloseableImage>>() {

        @Override
        protected void onNewResultImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
            if (!dataSource.isFinished()) {
                return;
            }
            CloseableReference<CloseableImage> ref = dataSource.getResult();
            if (ref != null && ref.isValid()) {
                try {
                    if (data.get(wrapperUri.getUri()) == null) {
                        holderData.put(holderUri, ref.clone());
                        if (imgDataLoadCompleteListener != null)
                            imgDataLoadCompleteListener.onHolderDataLoadComplete(wrapperUri);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    CloseableReference.closeSafely(ref);
                }
            }
        }

        @Override
        protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
        }
    }, UiThreadImmediateExecutorService.getInstance());
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) CloseableReference(com.facebook.common.references.CloseableReference) ImagePipeline(com.facebook.imagepipeline.core.ImagePipeline) Uri(android.net.Uri) WrapperUri(com.yioks.lzclib.Data.WrapperUri)

Aggregations

ImagePipeline (com.facebook.imagepipeline.core.ImagePipeline)22 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)17 CloseableReference (com.facebook.common.references.CloseableReference)16 Bitmap (android.graphics.Bitmap)10 DataSource (com.facebook.datasource.DataSource)10 BaseBitmapDataSubscriber (com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber)8 Uri (android.net.Uri)7 ImageRequestBuilder (com.facebook.imagepipeline.request.ImageRequestBuilder)5 CloseableImage (com.facebook.imagepipeline.image.CloseableImage)4 CloseableBitmap (com.facebook.imagepipeline.image.CloseableBitmap)3 File (java.io.File)3 FileOutputStream (java.io.FileOutputStream)3 SuppressLint (android.annotation.SuppressLint)2 ComponentName (android.content.ComponentName)2 RemoteViews (android.widget.RemoteViews)2 LatLng (com.amap.api.maps.model.LatLng)2 BinaryResource (com.facebook.binaryresource.BinaryResource)2 FileBinaryResource (com.facebook.binaryresource.FileBinaryResource)2 DiskCacheConfig (com.facebook.cache.disk.DiskCacheConfig)2 PooledByteBuffer (com.facebook.common.memory.PooledByteBuffer)2