Search in sources :

Example 86 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 87 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project BigImageViewer by Piasy.

the class FrescoImageLoader method loadImage.

@SuppressLint("WrongThread")
@Override
public void loadImage(final int requestId, Uri uri, final Callback callback) {
    ImageRequest request = ImageRequest.fromUri(uri);
    final File localCache = getCacheFile(request);
    if (localCache.exists()) {
        mExecutorSupplier.forLocalStorageRead().execute(new Runnable() {

            @Override
            public void run() {
                callback.onCacheHit(ImageInfoExtractor.getImageType(localCache), localCache);
                callback.onSuccess(localCache);
            }
        });
    } else {
        // ensure `onStart` is called before `onProgress` and `onFinish`
        callback.onStart();
        // show 0 progress immediately
        callback.onProgress(0);
        ImagePipeline pipeline = Fresco.getImagePipeline();
        DataSource<CloseableReference<PooledByteBuffer>> source = pipeline.fetchEncodedImage(request, true);
        source.subscribe(new ImageDownloadSubscriber(mAppContext) {

            @Override
            protected void onProgress(int progress) {
                callback.onProgress(progress);
            }

            @Override
            protected void onSuccess(final File image) {
                rememberTempFile(requestId, image);
                callback.onFinish();
                callback.onCacheMiss(ImageInfoExtractor.getImageType(image), image);
                callback.onSuccess(image);
            }

            @Override
            protected void onFail(final Throwable t) {
                t.printStackTrace();
                callback.onFail((Exception) t);
            }
        }, mExecutorSupplier.forBackgroundTasks());
        cancel(requestId);
        rememberSource(requestId, source);
    }
}
Also used : ImageRequest(com.facebook.imagepipeline.request.ImageRequest) CloseableReference(com.facebook.common.references.CloseableReference) ImagePipeline(com.facebook.imagepipeline.core.ImagePipeline) File(java.io.File) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Example 88 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 89 with ImageRequest

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

the class PhotoOverviewAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final SimpleViewHolder holder, final int position) {
    final Uri photoUri = diaryPhotoFileList.get(position);
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(diaryPhotoFileList.get(position)).setResizeOptions(new ResizeOptions(resizePhotoWidth, resizePhotoHeight)).build();
    DraweeController controller = Fresco.newDraweeControllerBuilder().setImageRequest(request).setTapToRetryEnabled(false).build();
    holder.SDV_CV_diary_photo_overview.setController(controller);
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) DraweeController(com.facebook.drawee.interfaces.DraweeController) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) Uri(android.net.Uri)

Example 90 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project ride-read-android by Ride-Read.

the class FrescoImgLoader method displayImage.

@Override
public void displayImage(Activity activity, Context context, String path, final GalleryImageView imageView, int width, int height) {
    GenericDraweeHierarchy hierarchy = // 占位图
    new GenericDraweeHierarchyBuilder(context.getResources()).setFadeDuration(300).setPlaceholderImage(R.mipmap.gallery_pick_photo).setFailureImage(// 加载失败图
    R.mipmap.gallery_pick_photo).setProgressBarImage(// loading
    new ProgressBarDrawable()).build();
    final DraweeHolder<GenericDraweeHierarchy> draweeHolder = DraweeHolder.create(hierarchy, context);
    imageView.setOnImageViewListener(new GalleryImageView.OnImageViewListener() {

        @Override
        public void onDraw(Canvas canvas) {
            Drawable drawable = draweeHolder.getHierarchy().getTopLevelDrawable();
            if (drawable == null) {
                imageView.setImageResource(R.mipmap.gallery_pick_photo);
            } else {
                imageView.setImageDrawable(drawable);
            }
        }

        @Override
        public boolean verifyDrawable(Drawable dr) {
            return dr == draweeHolder.getHierarchy().getTopLevelDrawable();
        }

        @Override
        public void onDetach() {
            draweeHolder.onDetach();
        }

        @Override
        public void onAttach() {
            draweeHolder.onAttach();
        }
    });
    Uri uri = new Uri.Builder().scheme(UriUtil.LOCAL_FILE_SCHEME).path(path).build();
    ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(uri).setResizeOptions(new ResizeOptions(width, height)).build();
    DraweeController controller = Fresco.newDraweeControllerBuilder().setOldController(draweeHolder.getController()).setImageRequest(imageRequest).build();
    draweeHolder.setController(controller);
}
Also used : GalleryImageView(com.yancy.gallerypick.widget.GalleryImageView) ProgressBarDrawable(com.facebook.drawee.drawable.ProgressBarDrawable) GenericDraweeHierarchy(com.facebook.drawee.generic.GenericDraweeHierarchy) GenericDraweeHierarchyBuilder(com.facebook.drawee.generic.GenericDraweeHierarchyBuilder) DraweeController(com.facebook.drawee.interfaces.DraweeController) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) ProgressBarDrawable(com.facebook.drawee.drawable.ProgressBarDrawable) Uri(android.net.Uri) ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest)

Aggregations

ImageRequest (com.facebook.imagepipeline.request.ImageRequest)100 ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)26 DraweeController (com.facebook.drawee.interfaces.DraweeController)25 CloseableReference (com.facebook.common.references.CloseableReference)24 Uri (android.net.Uri)18 ImagePipeline (com.facebook.imagepipeline.core.ImagePipeline)17 Test (org.junit.Test)14 Bitmap (android.graphics.Bitmap)13 CacheKey (com.facebook.cache.common.CacheKey)12 File (java.io.File)11 DataSource (com.facebook.datasource.DataSource)10 BaseBitmapDataSubscriber (com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber)9 CloseableImage (com.facebook.imagepipeline.image.CloseableImage)8 ImageRequestBuilder (com.facebook.imagepipeline.request.ImageRequestBuilder)8 Animatable (android.graphics.drawable.Animatable)7 PipelineDraweeController (com.facebook.drawee.backends.pipeline.PipelineDraweeController)7 BaseControllerListener (com.facebook.drawee.controller.BaseControllerListener)7 ImageOptions (com.facebook.fresco.vito.options.ImageOptions)7 ImageInfo (com.facebook.imagepipeline.image.ImageInfo)7 EncodedImage (com.facebook.imagepipeline.image.EncodedImage)6