Search in sources :

Example 41 with ResizeOptions

use of com.facebook.imagepipeline.common.ResizeOptions 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.boxing_app_name);
            if (path == null || absPath.equals(path)) {
                if (dataSource.getResult() == null) {
                    onFailureImpl(dataSource);
                    return;
                }
                Drawable drawable = createDrawableFromFetchedResult(img.getContext(), dataSource.getResult().get());
                img.setImageDrawable(drawable);
            }
        }

        @Override
        protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
            img.setImageResource(R.drawable.ic_boxing_broken_image);
        }
    }, UiThreadImmediateExecutorService.getInstance());
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) CloseableReference(com.facebook.common.references.CloseableReference) Drawable(android.graphics.drawable.Drawable) AnimatedDrawable(com.facebook.imagepipeline.animated.base.AnimatedDrawable) OrientedDrawable(com.facebook.drawee.drawable.OrientedDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ImageRequestBuilder(com.facebook.imagepipeline.request.ImageRequestBuilder)

Example 42 with ResizeOptions

use of com.facebook.imagepipeline.common.ResizeOptions in project boxing by Bilibili.

the class BoxingFrescoLoader method displayRaw.

@Override
public void displayRaw(@NonNull ImageView img, @NonNull String absPath, int width, int height, IBoxingCallback callback) {
    absPath = "file://" + absPath;
    ImageRequestBuilder requestBuilder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(absPath));
    if (width > 0 && height > 0) {
        requestBuilder.setResizeOptions(new ResizeOptions(width, height));
    }
    ImageRequest request = requestBuilder.build();
    loadImage(request, img, callback);
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) ImageRequestBuilder(com.facebook.imagepipeline.request.ImageRequestBuilder)

Example 43 with ResizeOptions

use of com.facebook.imagepipeline.common.ResizeOptions in project SherlockAdapter by EvilBT.

the class FrescoUtil method resizeImage.

public static void resizeImage(@NonNull final SimpleDraweeView view, @NonNull final String path, final int viewWidth) {
    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) {
                final int viewHeight = (int) (height * viewWidth / width);
                setResizeImage(view, path, new ResizeOptions(viewWidth, viewHeight));
            }
        }
    };
    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) ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) Animatable(android.graphics.drawable.Animatable) ImageInfo(com.facebook.imagepipeline.image.ImageInfo) Point(android.graphics.Point)

Example 44 with ResizeOptions

use of com.facebook.imagepipeline.common.ResizeOptions in project SherlockAdapter by EvilBT.

the class FrescoUtil method setWrapAndResizeImage.

public static void setWrapAndResizeImage(@NonNull final SimpleDraweeView view, @NonNull final String path, final int viewWidth, @Nullable final Point size) {
    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);
                final int viewHeight = (int) (height * viewWidth / width);
                if (size != null) {
                    size.set(viewWidth, viewHeight);
                }
                setResizeImage(view, path, new ResizeOptions(viewWidth, viewHeight));
            }
        }
    };
    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) ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) Animatable(android.graphics.drawable.Animatable) ImageInfo(com.facebook.imagepipeline.image.ImageInfo) Point(android.graphics.Point)

Example 45 with ResizeOptions

use of com.facebook.imagepipeline.common.ResizeOptions in project GalleryFinal by pengjianbo.

the class FrescoImageLoader method displayImage.

@Override
public void displayImage(Activity activity, String path, final GFImageView imageView, final Drawable defaultDrawable, int width, int height) {
    Resources resources = context.getResources();
    GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(resources).setFadeDuration(300).setPlaceholderImage(defaultDrawable).setFailureImage(defaultDrawable).setProgressBarImage(new ProgressBarDrawable()).build();
    final DraweeHolder<GenericDraweeHierarchy> draweeHolder = DraweeHolder.create(hierarchy, context);
    imageView.setOnImageViewListener(new GFImageView.OnImageViewListener() {

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

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

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

        @Override
        public void onDraw(Canvas canvas) {
            Drawable drawable = draweeHolder.getHierarchy().getTopLevelDrawable();
            if (drawable == null) {
                imageView.setImageDrawable(defaultDrawable);
            } else {
                imageView.setImageDrawable(drawable);
            }
        }
    });
    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 : 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) Resources(android.content.res.Resources) GFImageView(cn.finalteam.galleryfinal.widget.GFImageView)

Aggregations

ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)59 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)27 Uri (android.net.Uri)12 Test (org.junit.Test)11 DraweeController (com.facebook.drawee.interfaces.DraweeController)10 ImageRequestBuilder (com.facebook.imagepipeline.request.ImageRequestBuilder)7 PipelineDraweeController (com.facebook.drawee.backends.pipeline.PipelineDraweeController)5 File (java.io.File)5 PipelineDraweeControllerBuilder (com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder)4 Drawable (android.graphics.drawable.Drawable)3 CloseableReference (com.facebook.common.references.CloseableReference)3 GenericDraweeHierarchy (com.facebook.drawee.generic.GenericDraweeHierarchy)3 EncodedImage (com.facebook.imagepipeline.image.EncodedImage)3 FileSystemReference (im.actor.runtime.files.FileSystemReference)3 Context (android.content.Context)2 Canvas (android.graphics.Canvas)2 Point (android.graphics.Point)2 Animatable (android.graphics.drawable.Animatable)2 View (android.view.View)2 Spinner (android.widget.Spinner)2