Java Code Examples for com.facebook.imagepipeline.request.ImageRequestBuilder#setResizeOptions()

The following examples show how to use com.facebook.imagepipeline.request.ImageRequestBuilder#setResizeOptions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FrescoImageLoader.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public static void display(SimpleDraweeView view, String uri, int width, int height, ControllerListener listener) {
    if (uri != null) {
        PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder();
        controller.setOldController(view.getController());
        controller.setAutoPlayAnimations(true);
        ImageRequestBuilder imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(uri)).setCacheChoice(CacheChoice.SMALL).setLocalThumbnailPreviewsEnabled(true);
        imageRequest.setProgressiveRenderingEnabled(true);
        Log.d("Good", uri);
        if (width > 0 && height > 0) {
            imageRequest.setResizeOptions(new ResizeOptions(width, height));
        }
        controller.setImageRequest(imageRequest.build());
        controller.setControllerListener(listener);
        view.setController(controller.build());
    }
}
 
Example 2
Source File: FrescoHolder.java    From fresco with MIT License 6 votes vote down vote up
@Override
protected void onBind(String uriString) {
  Uri uri = Uri.parse(uriString);
  ImageRequestBuilder imageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(uri);
  if (UriUtil.isNetworkUri(uri)) {
    imageRequestBuilder.setProgressiveRenderingEnabled(true);
  } else {
    imageRequestBuilder.setResizeOptions(
        new ResizeOptions(
            mImageView.getLayoutParams().width, mImageView.getLayoutParams().height));
  }
  DraweeController draweeController =
      Fresco.newDraweeControllerBuilder()
          .setImageRequest(imageRequestBuilder.build())
          .setOldController(mImageView.getController())
          .setControllerListener(mImageView.getListener())
          .setAutoPlayAnimations(true)
          .build();
  mImageView.setController(draweeController);
}
 
Example 3
Source File: FrescoUtils.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public static void displayPhoto(SimpleDraweeView mSimpleDraweeView, String path, int width, int height) {
    if (!TextUtils.isEmpty(path)) {
        PipelineDraweeControllerBuilder mPipelineDraweeControllerBuilder = Fresco.newDraweeControllerBuilder();
        ImageRequestBuilder mImageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(path));
        mImageRequestBuilder.setResizeOptions(new ResizeOptions(width, height));
        mPipelineDraweeControllerBuilder.setOldController(mSimpleDraweeView.getController());
        mPipelineDraweeControllerBuilder.setImageRequest(mImageRequestBuilder.build());
        mSimpleDraweeView.setController(mPipelineDraweeControllerBuilder.build());
    }
}
 
Example 4
Source File: FrescoUtils.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public static void displayPhoto(SimpleDraweeView mSimpleDraweeView, String path, int width, int height, ControllerListener mControllerListener) {
    if (!TextUtils.isEmpty(path)) {
        PipelineDraweeControllerBuilder mPipelineDraweeControllerBuilder = Fresco.newDraweeControllerBuilder();
        ImageRequestBuilder mImageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(path));
        mImageRequestBuilder.setResizeOptions(new ResizeOptions(width, height));
        mPipelineDraweeControllerBuilder.setOldController(mSimpleDraweeView.getController());
        mPipelineDraweeControllerBuilder.setImageRequest(mImageRequestBuilder.build());
        mPipelineDraweeControllerBuilder.setControllerListener(mControllerListener);
        mSimpleDraweeView.setController(mPipelineDraweeControllerBuilder.build());
    }
}
 
Example 5
Source File: FrescoImageLoader.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public static void display(SimpleDraweeView view, String lowUri, String uri, ControllerListener listener) {
    if (uri != null) {
        ImageRequestBuilder imageRequest;
        int w = view.getLayoutParams().width;
        int h = view.getLayoutParams().height;
        PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder();
        if (!lowUri.startsWith("file:///")) {
            lowUri = "file://" + lowUri;
        }
        if (lowUri != null && lowUri.length() > 0) {
            controller.setLowResImageRequest(ImageRequest.fromUri(lowUri));
        }
        controller.setOldController(view.getController());
        controller.setAutoPlayAnimations(true);
        if (uri.endsWith(".MP4")) {
            imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(lowUri));
        } else {
            imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(uri));
        }
        if (w > 0 && h > 0) {
            imageRequest.setResizeOptions(new ResizeOptions(w, h));
        }
        controller.setImageRequest(imageRequest.build());
        controller.setControllerListener(listener);
        view.setController(controller.build());
    }
}
 
Example 6
Source File: FrescoController.java    From base-module with Apache License 2.0 5 votes vote down vote up
/**
 * 加载图片到 View 上,可设置回调监听
 * @param draweeView
 * @param listener
 */
public void intoTarget(SimpleDraweeView draweeView, ControllerListener listener) {
    if ((mImageConfig != null && mImageConfig.useNewHierarchy) || !draweeView.hasHierarchy()) {
        GenericDraweeHierarchy hierarchy = GenericDraweeHierarchyBuilder
                .newInstance(draweeView.getResources()).build();
        draweeView.setHierarchy(hierarchy);
    }
    parseImageConfig(draweeView.getHierarchy());
    if (mUri != null) {
        ImageDecodeOptions imageDecodeOptions = ImageDecodeOptions.newBuilder()
                .setDecodePreviewFrame(true)
                .build();
        ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(mUri)
                .setProgressiveRenderingEnabled(true)
                .setImageDecodeOptions(imageDecodeOptions);
        if (mWidth > 0 && mHeight > 0) {
            builder.setResizeOptions(new ResizeOptions(mWidth, mHeight));
        } else {
            int width = draweeView.getMeasuredWidth();
            int height = draweeView.getMeasuredHeight();
            if(width > 0 && height > 0){
                builder.setResizeOptions(new ResizeOptions(width, height));
            }
        }

        ImageRequest request = builder.build();
        AbstractDraweeController controller = Fresco.newDraweeControllerBuilder()
                .setImageRequest(request)
                .setControllerListener(listener)
                .setOldController(draweeView.getController())
                .setAutoPlayAnimations(true)
                .build();
        draweeView.setController(controller);
    } else {
        draweeView.setImageURI("");
    }
}
 
Example 7
Source File: FrescoController.java    From base-module with Apache License 2.0 5 votes vote down vote up
/**
 * 加载图片获取 Bitmap 对象
 * @param subscriber
 */
public void intoTarget(BaseBitmapDataSubscriber subscriber) {
    ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(mUri)
            .setProgressiveRenderingEnabled(true);

    if (mWidth > 0 && mHeight > 0) {
        builder.setResizeOptions(new ResizeOptions(mWidth, mHeight));
    }

    ImageRequest imageRequest = builder.build();
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, this);
    dataSource.subscribe(subscriber, UiThreadImmediateExecutorService.getInstance());
}
 
Example 8
Source File: BoxingFrescoLoader.java    From boxing with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 9
Source File: UniversalDraweeView.java    From JianshuApp with GNU General Public License v3.0 5 votes vote down vote up
private void loadImageURI(Uri uri, @Nullable Object callerContext, int width, int height) {
    // 对URL做格式转换、尺寸限制等处理
    uri = Uri.parse(ImageUtils.format(uri.toString(), DisplayInfo.getWidthPixels()));

    ImageRequestBuilder imageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(uri);
    imageRequestBuilder.setProgressiveRenderingEnabled(true);

    imageRequestBuilder.setRotationOptions(RotationOptions.autoRotateAtRenderTime());
    if (width > 0 && height > 0) {
        imageRequestBuilder.setResizeOptions(new ResizeOptions(width, height));
    }

    PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder()
            .setCallerContext(callerContext)
            .setImageRequest(imageRequestBuilder.build())
            .setOldController(getController())
            .setAutoPlayAnimations(true)  // 自动播放动态图
            .setTapToRetryEnabled(true)  // 在加载失败时,可以点击重新加载
            .setControllerListener(new BaseControllerListener<ImageInfo>() {
                @Override
                public void onFinalImageSet(String id,
                                            ImageInfo imageInfo,
                                            Animatable animatable) {
                    super.onFinalImageSet(id, imageInfo, animatable);
                    onUpdateImage(imageInfo);
                }
            });
    if (AppUtils.isMainThread()) {
        setController(controller.build());
    } else {
        Observable.just(0)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(it -> setController(controller.build()));
    }
}
 
Example 10
Source File: FrescoPlusFetcher.java    From FrescoPlus with Apache License 2.0 4 votes vote down vote up
/**
 * @param frescoPlusView The draweeView is to display the bitmap
 * @param uri         The source uri
 * @param callback    Listening to the success or failure
 */
private void fetchImage(FrescoPlusView frescoPlusView, Uri uri, FPFetchCallback<ImageInfo> callback) {
    GenericDraweeHierarchyBuilder hierarchyBuilder = new GenericDraweeHierarchyBuilder(null);
    hierarchyBuilder.setFadeDuration(fadeDuration);
    hierarchyBuilder.setRoundingParams(RoundingParams.fromCornersRadius(radius));
    hierarchyBuilder.setActualImageScaleType(scaleType);
    if (defaultDrawable != null)
        hierarchyBuilder.setPlaceholderImage(defaultDrawable, scaleType);
    if (pressedDrawable != null)
        hierarchyBuilder.setPressedStateOverlay(pressedDrawable);
    if (retryDrawable != null)
        hierarchyBuilder.setRetryImage(retryDrawable);
    if (overlayDrawable != null)
        hierarchyBuilder.setOverlay(overlayDrawable);
    if (failureDrawable != null)
        hierarchyBuilder.setFailureImage(failureDrawable, scaleType);
    if (progressDrawable != null)
        hierarchyBuilder.setProgressBarImage(progressDrawable);
    GenericDraweeHierarchy hierarchy = hierarchyBuilder.build();

    ImageRequestBuilder requestBuilder = ImageRequestBuilder.newBuilderWithSource(uri);
    requestBuilder.setLowestPermittedRequestLevel(requestLevel);
    requestBuilder.setAutoRotateEnabled(autoRotateEnabled);
    if (postprocessor != null)
        requestBuilder.setPostprocessor(postprocessor);
    Priority priority = requestPriority == FrescoPriority.HIGH ? Priority.HIGH : Priority.MEDIUM;
    requestBuilder.setRequestPriority(priority);
    if (resizeWidth > 0 && resizeHeight > 0)
        requestBuilder.setResizeOptions(new ResizeOptions(resizeWidth, resizeHeight));
    ImageRequest imageRequest = requestBuilder.build();

    DraweeController draweeController = FrescoPlusCore.newDraweeControllerBuilder()
            .setOldController(frescoPlusView.getController())
            .setAutoPlayAnimations(true)
            .setRetainImageOnFailure(true)
            .setTapToRetryEnabled(true)
            .setImageRequest(imageRequest)
            .setControllerListener(FetchImageControllerListenerSupplier.newInstance(callback))
            .build();
    frescoPlusView.setHierarchy(hierarchy);
    frescoPlusView.setController(draweeController);
}
 
Example 11
Source File: FrescoImageLoader.java    From ScrollGalleryView with MIT License 4 votes vote down vote up
private ImageRequest createImageRequest(Integer thumbnailWidth, Integer thumbnailHeight) {
    ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url));
    builder.setResizeOptions(new ResizeOptions(thumbnailWidth, thumbnailHeight));

    return builder.build();
}
 
Example 12
Source File: ImagePipelineUtilsImpl.java    From fresco with MIT License 4 votes vote down vote up
@Nullable
protected ImageRequestBuilder createDecodedImageRequestBuilder(
    @Nullable ImageRequestBuilder imageRequestBuilder, DecodedImageOptions imageOptions) {
  if (imageRequestBuilder == null) {
    return null;
  }

  if (mExperiments.useNativeRounding() && NativeCodeSetup.getUseNativeCode()) {
    setupNativeRounding(imageRequestBuilder, imageOptions.getRoundingOptions());
  }

  ResizeOptions resizeOptions = imageOptions.getResizeOptions();
  if (resizeOptions != null) {
    imageRequestBuilder.setResizeOptions(resizeOptions);
  }

  RotationOptions rotationOptions = imageOptions.getRotationOptions();
  if (rotationOptions != null) {
    imageRequestBuilder.setRotationOptions(rotationOptions);
  }

  if (imageOptions.getBitmapConfig() != null) {
    if (imageOptions.getRoundingOptions() != null || imageOptions.getPostprocessor() != null) {
      FLog.wtf(TAG, "Trying to use bitmap config incompatible with rounding.");
    } else {
      imageRequestBuilder.setImageDecodeOptions(
          ImageDecodeOptions.newBuilder()
              .setBitmapConfig(imageOptions.getBitmapConfig())
              .setCustomImageDecoder(
                  imageOptions.getImageDecodeOptions() != null
                      ? imageOptions.getImageDecodeOptions().customImageDecoder
                      : null)
              .build());
    }
  } else if (imageOptions.getImageDecodeOptions() != null
      && imageOptions.getImageDecodeOptions().customImageDecoder != null) {
    imageRequestBuilder.setImageDecodeOptions(
        ImageDecodeOptions.newBuilder()
            .setCustomImageDecoder(imageOptions.getImageDecodeOptions().customImageDecoder)
            .build());
  }

  imageRequestBuilder.setLocalThumbnailPreviewsEnabled(
      imageOptions.areLocalThumbnailPreviewsEnabled());

  imageRequestBuilder.setShouldDecodePrefetches(mExperiments.prefetchToBitmapCache());

  imageRequestBuilder.setPostprocessor(imageOptions.getPostprocessor());

  return imageRequestBuilder;
}