Search in sources :

Example 31 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project teaTime by ancfdy.

the class FrescoUtils method localImg.

/**
     * 缩略图预览(仅支持本地图片,并且是JPEG图片格式)
     * @param draweeView
     * @param uri
     */
public static void localImg(SimpleDraweeView draweeView, Uri uri) {
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri).setLocalThumbnailPreviewsEnabled(true).build();
    DraweeController controller = Fresco.newDraweeControllerBuilder().setImageRequest(request).setOldController(draweeView.getController()).build();
    draweeView.setController(controller);
}
Also used : DraweeController(com.facebook.drawee.interfaces.DraweeController) ImageRequest(com.facebook.imagepipeline.request.ImageRequest)

Example 32 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project teaTime by ancfdy.

the class FrescoUtils method loadImage.

/**
     * 请求图片
     * @param uri - 唯一的必选的成员. 参考 支持的URIs
     * @param width
     * @param height
     * autoRotateEnabled - 是否支持自动旋转.
     * progressiveEnabled - 是否支持渐进式加载.
     * postprocessor - 后处理器(postprocess).
     * resizeOptions - 图片缩放选项,用前请先阅读缩放和旋转
     */
public static void loadImage(SimpleDraweeView draweeView, String uri, int width, int height) {
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(uri)).setAutoRotateEnabled(// 是否支持自动旋转.
    true).setImageDecodeOptions(//  图片解码库
    getImageDecodeOptions()).setLowestPermittedRequestLevel(//请求经过缓存级别  BITMAP_MEMORY_CACHE,ENCODED_MEMORY_CACHE,DISK_CACHE,FULL_FETCH
    RequestLevel.FULL_FETCH).setProgressiveRenderingEnabled(//渐进加载,主要用于渐进式的JPEG图,影响图片显示速度(普通)
    false).setResizeOptions(new ResizeOptions(width, height)).build();
    DraweeController controller = Fresco.newDraweeControllerBuilder().setImageRequest(request).setOldController(draweeView.getController()).build();
    draweeView.setController(controller);
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) DraweeController(com.facebook.drawee.interfaces.DraweeController) ImageRequest(com.facebook.imagepipeline.request.ImageRequest)

Example 33 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project SherlockAdapter by EvilBT.

the class FrescoUtil method setWrapImage.

public static void setWrapImage(@NonNull final SimpleDraweeView view, @NonNull final String path) {
    Preconditions.checkNotNull(view);
    Preconditions.checkNotNull(path);
    ControllerListener<ImageInfo> controllerListener = new BaseControllerListener<ImageInfo>() {

        @Override
        public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
            if (imageInfo == null) {
                return;
            }
            final float width = imageInfo.getWidth();
            final float height = imageInfo.getHeight();
            if (width * height != 0.0f) {
                view.setAspectRatio(width / height);
            }
        }
    };
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(path)).build();
    view.setController(Fresco.newDraweeControllerBuilder().setImageRequest(request).setOldController(view.getController()).setControllerListener(controllerListener).build());
}
Also used : BaseControllerListener(com.facebook.drawee.controller.BaseControllerListener) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) Animatable(android.graphics.drawable.Animatable) ImageInfo(com.facebook.imagepipeline.image.ImageInfo)

Example 34 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project SherlockAdapter by EvilBT.

the class FrescoUtil method setResizeImage.

public static void setResizeImage(@NonNull final SimpleDraweeView view, @NonNull final String path, @NonNull ResizeOptions resize) {
    Preconditions.checkNotNull(view);
    Preconditions.checkNotNull(path);
    Preconditions.checkNotNull(resize);
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(path)).setResizeOptions(resize).build();
    view.setController(Fresco.newDraweeControllerBuilder().setImageRequest(request).setOldController(view.getController()).setAutoPlayAnimations(true).build());
}
Also used : ImageRequest(com.facebook.imagepipeline.request.ImageRequest)

Example 35 with ImageRequest

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

the class FrescoManager method downLoadImage.

@Override
public void downLoadImage(Context context, String url, final File saveFile, final ImageListener<File> 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<PooledByteBuffer>> dataSource = imagePipeline.fetchEncodedImage(imageRequest, context);
    dataSource.subscribe(new BaseDataSubscriber<CloseableReference<PooledByteBuffer>>() {

        @Override
        public void onNewResultImpl(DataSource<CloseableReference<PooledByteBuffer>> dataSource) {
            if (!dataSource.isFinished()) {
                return;
            }
            CloseableReference<PooledByteBuffer> imageReference = dataSource.getResult();
            if (imageReference != null) {
                final CloseableReference<PooledByteBuffer> closeableReference = imageReference.clone();
                try {
                    PooledByteBuffer pooledByteBuffer = closeableReference.get();
                    InputStream inputStream = new PooledByteBufferInputStream(pooledByteBuffer);
                    OutputStream outputStream = new FileOutputStream(saveFile);
                    if (FileUtil.saveFile(inputStream, outputStream) && imageListener != null) {
                        imageListener.onSuccess(saveFile);
                    }
                } catch (Exception e) {
                    if (imageListener != null) {
                        imageListener.onFail(e);
                    }
                    e.printStackTrace();
                } finally {
                    imageReference.close();
                    closeableReference.close();
                }
            }
        }

        @Override
        public void onProgressUpdate(DataSource<CloseableReference<PooledByteBuffer>> dataSource) {
            int progress = (int) (dataSource.getProgress() * 100);
            RingLog.d("fresco下载图片进度:" + progress);
        }

        @Override
        public void onFailureImpl(DataSource dataSource) {
            Throwable throwable = dataSource.getFailureCause();
            if (imageListener != null) {
                imageListener.onFail(throwable);
            }
        }
    }, Executors.newSingleThreadExecutor());
}
Also used : PooledByteBufferInputStream(com.facebook.common.memory.PooledByteBufferInputStream) PooledByteBufferInputStream(com.facebook.common.memory.PooledByteBufferInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) CloseableReference(com.facebook.common.references.CloseableReference) Uri(android.net.Uri) DataSource(com.facebook.datasource.DataSource) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) FileOutputStream(java.io.FileOutputStream) PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) ImagePipeline(com.facebook.imagepipeline.core.ImagePipeline) ImageRequestBuilder(com.facebook.imagepipeline.request.ImageRequestBuilder)

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