com.facebook.imagepipeline.common.ResizeOptions Java Examples

The following examples show how to use com.facebook.imagepipeline.common.ResizeOptions. 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: CanPhotoHelper.java    From CanPhotos with Apache License 2.0 6 votes vote down vote up
/**
 * 设置图片
 *
 * @param image
 * @param url
 * @param width
 * @param heigth
 */
public void setDraweeImage(SimpleDraweeView image, String url, int width, int heigth) {


    if (width <= 0) {
        width = dp2Px(image.getContext(), 50);
    }
    if (heigth <= 0) {
        heigth = dp2Px(image.getContext(), 50);
    }

    ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url)).setLocalThumbnailPreviewsEnabled(true).setResizeOptions(new ResizeOptions(width, heigth)).build();
    DraweeController draweeController = Fresco.newDraweeControllerBuilder()
            .setImageRequest(imageRequest)
            .setAutoPlayAnimations(true)
            .build();
    image.setController(draweeController);

}
 
Example #2
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 #3
Source File: SingleImageInterceptor.java    From Flora with MIT License 6 votes vote down vote up
private void load(Uri uri, SimpleDraweeView draweeView, int width, int height) {
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri)
            .setResizeOptions(new ResizeOptions(width, height))
            .setProgressiveRenderingEnabled(true)
            .setAutoRotateEnabled(true)
            .build();

    PipelineDraweeController controller =
            (PipelineDraweeController) Fresco.newDraweeControllerBuilder()
                    .setImageRequest(request)
                    .setOldController(draweeView.getController())
                    .setAutoPlayAnimations(true)
                    .build();

    draweeView.setController(controller);
}
 
Example #4
Source File: CommentImageGrid.java    From CommentGallery with Apache License 2.0 6 votes vote down vote up
private void refreshImageChild() {
    int childrenCount = getChildCount();
    if (childrenCount > 0) {
        for (int i = 0; i < childrenCount; i++) {
            ViewGroup childImageLayout = (ViewGroup) getChildAt(i);
            SimpleDraweeView childImageView = (SimpleDraweeView) childImageLayout.getChildAt(0);
            if (mOnItemClickListener != null) {
                final int finalI = i;
                childImageLayout.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mOnItemClickListener.OnItemClick(finalI);
                    }
                });
            }
            ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(mImageUrls.get(i)))
                    .setResizeOptions(new ResizeOptions(mItemWidth, mItemWidth))
                    .build();
            DraweeController controller = Fresco.newDraweeControllerBuilder()
                    .setImageRequest(request)
                    .setOldController(childImageView.getController())
                    .build();
            childImageView.setController(controller);
        }
    }
}
 
Example #5
Source File: ThumbnailSizeCheckerTest.java    From fresco with MIT License 6 votes vote down vote up
private static void testWithImageNotBigEnoughForResizeOptions(
    int[] imageWidths,
    int[] imageHeights,
    int startRotation,
    int additionalRequestWidth,
    int additionalRequestHeight) {
  for (int rotation = startRotation; rotation < 360; rotation += 180) {
    for (int i = 0; i < TEST_COUNT; i++) {
      ResizeOptions resizeOptions =
          new ResizeOptions(
              REQUEST_WIDTHS[i] + additionalRequestWidth,
              REQUEST_HEIGHTS[i] + additionalRequestHeight);
      EncodedImage encodedImage = mockImage(imageWidths[i], imageHeights[i], rotation);
      assertFalse(ThumbnailSizeChecker.isImageBigEnough(encodedImage, resizeOptions));
    }
  }
}
 
Example #6
Source File: LocalContentUriThumbnailFetchProducer.java    From fresco with MIT License 6 votes vote down vote up
private @Nullable EncodedImage getCameraImage(Uri uri, @Nullable ResizeOptions resizeOptions)
    throws IOException {
  if (resizeOptions == null) {
    return null;
  }
  @Nullable Cursor cursor = mContentResolver.query(uri, PROJECTION, null, null, null);
  if (cursor == null) {
    return null;
  }
  try {
    if (cursor.moveToFirst()) {
      final int imageIdColumnIndex = cursor.getColumnIndex(MediaStore.Images.Media._ID);
      final EncodedImage thumbnail =
          getThumbnail(resizeOptions, cursor.getLong(imageIdColumnIndex));
      if (thumbnail != null) {
        final String pathname =
            cursor.getString(cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA));
        thumbnail.setRotationAngle(getRotationAngle(pathname));
        return thumbnail;
      }
    }
  } finally {
    cursor.close();
  }
  return null;
}
 
Example #7
Source File: ImageRequestTest.java    From fresco with MIT License 6 votes vote down vote up
@Test
public void testCreatingRequestFromExistingRequest() {
  ImageRequest original =
      ImageRequestBuilder.newBuilderWithSource(Uri.parse("http://frescolib.org/image.jpg"))
          .setCacheChoice(ImageRequest.CacheChoice.SMALL)
          .setImageDecodeOptions(new ImageDecodeOptionsBuilder().build())
          .setLocalThumbnailPreviewsEnabled(true)
          .setLowestPermittedRequestLevel(ImageRequest.RequestLevel.DISK_CACHE)
          .setPostprocessor(
              new BasePostprocessor() {
                @Override
                public String getName() {
                  return super.getName();
                }
              })
          .setProgressiveRenderingEnabled(true)
          .setRequestListener(new RequestLoggingListener())
          .setResizeOptions(new ResizeOptions(20, 20))
          .setRotationOptions(RotationOptions.forceRotation(RotationOptions.ROTATE_90))
          .setRequestPriority(Priority.HIGH)
          .build();

  ImageRequest copy = ImageRequestBuilder.fromRequest(original).build();

  assertThat(copy).isEqualTo(original);
}
 
Example #8
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 #9
Source File: ResizeAndRotateProducer.java    From FanXin-based-HuanXin with GNU General Public License v2.0 6 votes vote down vote up
private static int getScaleNumerator(
    final ImageRequest imageRequest,
    final ImageTransformMetaData metaData) {
  final ResizeOptions resizeOptions = imageRequest.getResizeOptions();
  if (resizeOptions == null) {
    return JpegTranscoder.SCALE_DENOMINATOR;
  }

  final int rotationAngle = getRotationAngle(imageRequest, metaData);
  final boolean swapDimensions = rotationAngle == 90 || rotationAngle == 270;
  final int widthAfterRotation = swapDimensions ? metaData.getHeight() : metaData.getWidth();
  final int heightAfterRotation = swapDimensions ? metaData.getWidth() : metaData.getHeight();

  final float widthRatio = ((float) resizeOptions.width) / widthAfterRotation;
  final float heightRatio = ((float) resizeOptions.height) / heightAfterRotation;
  final int numerator =
      (int) Math.ceil(Math.max(widthRatio, heightRatio) * JpegTranscoder.SCALE_DENOMINATOR);

  if (numerator > MAX_JPEG_SCALE_NUMERATOR) {
    return JpegTranscoder.SCALE_DENOMINATOR;
  }
  if (numerator < 1) {
    return 1;
  }
  return numerator;
}
 
Example #10
Source File: FrescoImageloadHelper.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
public static void LoadImageFromURLAndCallBack(SimpleDraweeView destImageView , String URL,Context context,BaseBitmapDataSubscriber bbds)
{
    int w = destImageView.getWidth();
    int h  =destImageView.getHeight();
    if(w<1){
        w = destImageView.getLayoutParams().width;
    }
    if(h<1){
        h  =destImageView.getLayoutParams().height;
    }
    ImageRequest imageRequest =
            ImageRequestBuilder.newBuilderWithSource(Uri.parse(URL))
                    .setResizeOptions(new ResizeOptions(w,h))
                    .setProgressiveRenderingEnabled(true)
                    .build();
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);
    dataSource.subscribe(bbds, CallerThreadExecutor.getInstance());
    DraweeController draweeController = Fresco.newDraweeControllerBuilder()
            .setImageRequest(imageRequest)
            .setOldController(destImageView.getController())
            .setAutoPlayAnimations(true)
            .build();
    destImageView.setController(draweeController);
}
 
Example #11
Source File: FrescoImageloadHelper.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
public static void LoadImageFromURIAndCallBack(SimpleDraweeView destImageView , Uri uri,Context context,BaseBitmapDataSubscriber bbds)
{
    int w = destImageView.getWidth();
    int h  =destImageView.getHeight();
    if(w<1){
        w = destImageView.getLayoutParams().width;
    }
    if(h<1){
        h  =destImageView.getLayoutParams().height;
    }
    ImageRequest imageRequest =
            ImageRequestBuilder.newBuilderWithSource(uri)
                    .setResizeOptions(new ResizeOptions(w,h))
                    .setProgressiveRenderingEnabled(true)
                    .build();
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);
    dataSource.subscribe(bbds, CallerThreadExecutor.getInstance());
    DraweeController draweeController = Fresco.newDraweeControllerBuilder()
            .setImageRequest(imageRequest)
            .setOldController(destImageView.getController())
            .setAutoPlayAnimations(true)
            .build();
    destImageView.setController(draweeController);
}
 
Example #12
Source File: BitmapMemoryCacheKey.java    From fresco with MIT License 6 votes vote down vote up
public BitmapMemoryCacheKey(
    String sourceString,
    @Nullable ResizeOptions resizeOptions,
    RotationOptions rotationOptions,
    ImageDecodeOptions imageDecodeOptions,
    @Nullable CacheKey postprocessorCacheKey,
    @Nullable String postprocessorName,
    Object callerContext) {
  mSourceString = Preconditions.checkNotNull(sourceString);
  mResizeOptions = resizeOptions;
  mRotationOptions = rotationOptions;
  mImageDecodeOptions = imageDecodeOptions;
  mPostprocessorCacheKey = postprocessorCacheKey;
  mPostprocessorName = postprocessorName;
  mHash =
      HashCodeUtil.hashCode(
          sourceString.hashCode(),
          (resizeOptions != null) ? resizeOptions.hashCode() : 0,
          rotationOptions.hashCode(),
          mImageDecodeOptions,
          mPostprocessorCacheKey,
          postprocessorName);
  mCallerContext = callerContext;
  mCacheTime = RealtimeSinceBootClock.get().now();
}
 
Example #13
Source File: DraweeViewHolder.java    From fresco with MIT License 6 votes vote down vote up
/** @param uri The Uri to show into the DraweeView for this Holder */
public void bind(Uri uri) {
  mDraweeView.initInstrumentation(uri.toString(), mPerfListener);
  ImageRequestBuilder imageRequestBuilder =
      ImageRequestBuilder.newBuilderWithSource(uri)
          .setResizeOptions(
              new ResizeOptions(
                  mDraweeView.getLayoutParams().width, mDraweeView.getLayoutParams().height));
  PipelineUtil.addOptionalFeatures(imageRequestBuilder, mConfig);
  // Create the Builder
  PipelineDraweeControllerBuilder builder =
      Fresco.newDraweeControllerBuilder().setImageRequest(imageRequestBuilder.build());
  if (mConfig.reuseOldController) {
    builder.setOldController(mDraweeView.getController());
  }
  mDraweeView.setListener(builder);
  mDraweeView.setController(builder.build());
}
 
Example #14
Source File: JpegTranscoderUtils.java    From fresco with MIT License 6 votes vote down vote up
@VisibleForTesting
public static float determineResizeRatio(ResizeOptions resizeOptions, int width, int height) {
  if (resizeOptions == null) {
    return 1.0f;
  }

  final float widthRatio = ((float) resizeOptions.width) / width;
  final float heightRatio = ((float) resizeOptions.height) / height;
  float ratio = Math.max(widthRatio, heightRatio);

  if (width * ratio > resizeOptions.maxBitmapSize) {
    ratio = resizeOptions.maxBitmapSize / width;
  }
  if (height * ratio > resizeOptions.maxBitmapSize) {
    ratio = resizeOptions.maxBitmapSize / height;
  }
  return ratio;
}
 
Example #15
Source File: ImageAdapter.java    From TLint with Apache License 2.0 6 votes vote down vote up
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    Image image = images.get(position);
    holder.image = image;
    if (image == null) {
        return;
    }
    holder.ivCheck.setVisibility(View.VISIBLE);
    holder.ivCheck.setImageResource(selectedImages.contains(image) ? R.drawable.ap_gallery_checked
            : R.drawable.ap_gallery_normal);
    int width = 100, height = 100;
    ImageRequest request =
            ImageRequestBuilder.newBuilderWithSource(Uri.fromFile(new File(image.path)))
                    .setResizeOptions(new ResizeOptions(width, height))
                    .build();
    PipelineDraweeController controller =
            (PipelineDraweeController) Fresco.newDraweeControllerBuilder()
                    .setOldController(holder.ivPhoto.getController())
                    .setImageRequest(request)
                    .build();
    holder.ivPhoto.setController(controller);
}
 
Example #16
Source File: LocalContentUriThumbnailFetchProducer.java    From fresco with MIT License 5 votes vote down vote up
private @Nullable EncodedImage getThumbnail(ResizeOptions resizeOptions, long imageId)
    throws IOException {
  int thumbnailKind = getThumbnailKind(resizeOptions);
  if (thumbnailKind == NO_THUMBNAIL) {
    return null;
  }
  @Nullable
  Cursor thumbnailCursor =
      MediaStore.Images.Thumbnails.queryMiniThumbnail(
          mContentResolver, imageId, thumbnailKind, THUMBNAIL_PROJECTION);
  if (thumbnailCursor == null) {
    return null;
  }
  try {
    if (thumbnailCursor.moveToFirst()) {
      final String thumbnailUri =
          thumbnailCursor.getString(
              thumbnailCursor.getColumnIndex(MediaStore.Images.Thumbnails.DATA));
      if (new File(thumbnailUri).exists()) {
        return getEncodedImage(new FileInputStream(thumbnailUri), getLength(thumbnailUri));
      }
    }
  } finally {
    thumbnailCursor.close();
  }
  return null;
}
 
Example #17
Source File: DecodeProducerTest.java    From fresco with MIT License 5 votes vote down vote up
@Test
public void testDecode_WhenSmartResizingEnabledAndLocalUri_ThenPerformDownsampling()
    throws Exception {
  int resizedWidth = 10;
  int resizedHeight = 10;
  setupLocalUri(ResizeOptions.forDimensions(resizedWidth, resizedHeight));

  produceResults();
  JobScheduler.JobRunnable jobRunnable = getJobRunnable();

  jobRunnable.run(mEncodedImage, Consumer.IS_LAST);

  // The sample size was modified, which means Downsampling has been performed
  assertNotEquals(mEncodedImage.getSampleSize(), EncodedImage.DEFAULT_SAMPLE_SIZE);
}
 
Example #18
Source File: LocalContentUriThumbnailFetchProducer.java    From fresco with MIT License 5 votes vote down vote up
private static int getThumbnailKind(ResizeOptions resizeOptions) {
  if (ThumbnailSizeChecker.isImageBigEnough(
      MICRO_THUMBNAIL_DIMENSIONS.width(), MICRO_THUMBNAIL_DIMENSIONS.height(), resizeOptions)) {
    return MediaStore.Images.Thumbnails.MICRO_KIND;
  } else if (ThumbnailSizeChecker.isImageBigEnough(
      MINI_THUMBNAIL_DIMENSIONS.width(), MINI_THUMBNAIL_DIMENSIONS.height(), resizeOptions)) {
    return MediaStore.Images.Thumbnails.MINI_KIND;
  } else {
    return NO_THUMBNAIL;
  }
}
 
Example #19
Source File: ThumbnailSizeCheckerTest.java    From fresco with MIT License 5 votes vote down vote up
@Test
public void testWithWidthAndHeightAndResizeOptionsNotMoreThan133PercentOfActual() {
  for (int i = 0; i < TEST_COUNT; i++) {
    ResizeOptions resizeOptions = new ResizeOptions(REQUEST_WIDTHS[i], REQUEST_HEIGHTS[i]);
    assertTrue(
        ThumbnailSizeChecker.isImageBigEnough(IMAGE_WIDTHS[i], IMAGE_HEIGHTS[i], resizeOptions));
  }
}
 
Example #20
Source File: ResizeAndRotateProducer.java    From fresco with MIT License 5 votes vote down vote up
private @Nullable Map<String, String> getExtraMap(
    EncodedImage encodedImage,
    @Nullable ResizeOptions resizeOptions,
    @Nullable ImageTranscodeResult transcodeResult,
    @Nullable String transcoderId) {
  if (!mProducerContext
      .getProducerListener()
      .requiresExtraMap(mProducerContext, PRODUCER_NAME)) {
    return null;
  }
  String originalSize = encodedImage.getWidth() + "x" + encodedImage.getHeight();

  String requestedSize;
  if (resizeOptions != null) {
    requestedSize = resizeOptions.width + "x" + resizeOptions.height;
  } else {
    requestedSize = "Unspecified";
  }

  final Map<String, String> map = new HashMap<>();
  map.put(INPUT_IMAGE_FORMAT, String.valueOf(encodedImage.getImageFormat()));
  map.put(ORIGINAL_SIZE_KEY, originalSize);
  map.put(REQUESTED_SIZE_KEY, requestedSize);
  map.put(JobScheduler.QUEUE_TIME_KEY, String.valueOf(mJobScheduler.getQueuedTime()));
  map.put(TRANSCODER_ID, transcoderId);
  map.put(TRANSCODING_RESULT, String.valueOf(transcodeResult));
  return ImmutableMap.copyOf(map);
}
 
Example #21
Source File: ThumbnailBranchProducerTest.java    From fresco with MIT License 5 votes vote down vote up
@Test
public void testNullReturnedIfNoProducerSufficientForResizeOptions() {
  int width = THUMBNAIL_WIDTHS[2] + 50;
  int height = THUMBNAIL_HEIGHTS[2] + 50;
  mockRequestWithResizeOptions(width, height);

  mProducer.produceResults(mImageConsumer, mProducerContext);

  verify(mImageConsumer).onNewResult(null, Consumer.IS_LAST);
  ResizeOptions resizeOptions = new ResizeOptions(width, height);
  verify(mThumbnailProducers[0]).canProvideImageForSize(resizeOptions);
  verify(mThumbnailProducers[1]).canProvideImageForSize(resizeOptions);
  verify(mThumbnailProducers[2]).canProvideImageForSize(resizeOptions);
  verifyNoMoreInteractions((Object[]) mThumbnailProducers);
}
 
Example #22
Source File: NativeJpegTranscoder.java    From fresco with MIT License 5 votes vote down vote up
@Override
public boolean canResize(
    EncodedImage encodedImage,
    @Nullable RotationOptions rotationOptions,
    @Nullable ResizeOptions resizeOptions) {
  if (rotationOptions == null) {
    rotationOptions = RotationOptions.autoRotate();
  }
  return JpegTranscoderUtils.getSoftwareNumerator(
          rotationOptions, resizeOptions, encodedImage, mResizingEnabled)
      < JpegTranscoderUtils.SCALE_DENOMINATOR;
}
 
Example #23
Source File: ImagePipelineUtilsImplTest.java    From fresco with MIT License 5 votes vote down vote up
@Test
public void testBuildImageRequest_whenResizingEnabled_thenSetResizeOptions() {
  ResizeOptions resizeOptions = ResizeOptions.forDimensions(123, 234);
  final ImageOptions imageOptions = ImageOptions.create().resize(resizeOptions).build();

  ImageRequest imageRequest = mImagePipelineUtils.buildImageRequest(URI, imageOptions);

  assertThat(imageRequest).isNotNull();
  assertThat(imageRequest.getSourceUri()).isEqualTo(URI);
  assertThat(imageRequest.getResizeOptions()).isEqualTo(resizeOptions);
}
 
Example #24
Source File: DownsampleUtil.java    From fresco with MIT License 5 votes vote down vote up
@VisibleForTesting
public static float determineDownsampleRatio(
    final RotationOptions rotationOptions,
    @Nullable final ResizeOptions resizeOptions,
    final EncodedImage encodedImage) {
  Preconditions.checkArgument(EncodedImage.isMetaDataAvailable(encodedImage));
  if (resizeOptions == null
      || resizeOptions.height <= 0
      || resizeOptions.width <= 0
      || encodedImage.getWidth() == 0
      || encodedImage.getHeight() == 0) {
    return 1.0f;
  }

  final int rotationAngle = getRotationAngle(rotationOptions, encodedImage);
  final boolean swapDimensions = rotationAngle == 90 || rotationAngle == 270;
  final int widthAfterRotation =
      swapDimensions ? encodedImage.getHeight() : encodedImage.getWidth();
  final int heightAfterRotation =
      swapDimensions ? encodedImage.getWidth() : encodedImage.getHeight();

  final float widthRatio = ((float) resizeOptions.width) / widthAfterRotation;
  final float heightRatio = ((float) resizeOptions.height) / heightAfterRotation;
  float ratio = Math.max(widthRatio, heightRatio);
  FLog.v(
      "DownsampleUtil",
      "Downsample - Specified size: %dx%d, image size: %dx%d "
          + "ratio: %.1f x %.1f, ratio: %.3f",
      resizeOptions.width,
      resizeOptions.height,
      widthAfterRotation,
      heightAfterRotation,
      widthRatio,
      heightRatio,
      ratio);
  return ratio;
}
 
Example #25
Source File: ThumbnailBranchProducerTest.java    From fresco with MIT License 5 votes vote down vote up
private static void mockProducerToSupportSize(
    ThumbnailProducer<EncodedImage> mockProducer, final int width, final int height) {
  when(mockProducer.canProvideImageForSize(any(ResizeOptions.class)))
      .then(
          new Answer<Boolean>() {
            @Override
            public Boolean answer(InvocationOnMock invocation) throws Throwable {
              ResizeOptions resizeOptions = (ResizeOptions) invocation.getArguments()[0];
              return resizeOptions.width <= width && resizeOptions.height <= height;
            }
          });
}
 
Example #26
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 #27
Source File: ResizeAndRotateProducerTest.java    From fresco with MIT License 5 votes vote down vote up
@Test
public void testResizeRatio() {
  ResizeOptions resizeOptions = new ResizeOptions(512, 512);
  assertEquals(0.5f, JpegTranscoderUtils.determineResizeRatio(resizeOptions, 1024, 1024), 0.01);
  assertEquals(0.25f, JpegTranscoderUtils.determineResizeRatio(resizeOptions, 2048, 4096), 0.01);
  assertEquals(0.5f, JpegTranscoderUtils.determineResizeRatio(resizeOptions, 4096, 512), 0.01);
}
 
Example #28
Source File: DraweeViewListAdapter.java    From fresco with MIT License 5 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
  InstrumentedDraweeView draweeView;
  if (convertView == null) {
    final Context context = parent.getContext();
    GenericDraweeHierarchy gdh = DraweeUtil.createDraweeHierarchy(context, mConfig);
    draweeView = new InstrumentedDraweeView(context, gdh, mConfig);
    SizeUtil.setConfiguredSize(parent, draweeView, mConfig);
    draweeView.setPadding(mPaddingPx, mPaddingPx, mPaddingPx, mPaddingPx);
  } else {
    draweeView = (InstrumentedDraweeView) convertView;
  }
  final Uri uri = getItem(position);
  draweeView.initInstrumentation(uri.toString(), mPerfListener);
  ImageRequestBuilder imageRequestBuilder =
      ImageRequestBuilder.newBuilderWithSource(uri)
          .setResizeOptions(
              new ResizeOptions(
                  draweeView.getLayoutParams().width, draweeView.getLayoutParams().height));
  PipelineUtil.addOptionalFeatures(imageRequestBuilder, mConfig);
  // Create the Builder
  PipelineDraweeControllerBuilder builder =
      Fresco.newDraweeControllerBuilder().setImageRequest(imageRequestBuilder.build());
  if (mConfig.reuseOldController) {
    builder.setOldController(draweeView.getController());
  }
  if (mConfig.instrumentationEnabled) {
    draweeView.setListener(builder);
  }
  draweeView.setController(builder.build());
  return draweeView;
}
 
Example #29
Source File: DownsampleUtilTest.java    From fresco with MIT License 5 votes vote down vote up
private void whenRequestResizeWidthHeightAndForcedRotation(
    int width, int height, int rotationAngle) {
  when(mImageRequest.getPreferredWidth()).thenReturn(width);
  when(mImageRequest.getPreferredHeight()).thenReturn(height);
  when(mImageRequest.getResizeOptions()).thenReturn(new ResizeOptions(width, height));
  when(mImageRequest.getRotationOptions())
      .thenReturn(RotationOptions.forceRotation(rotationAngle));
}
 
Example #30
Source File: ThumbnailBranchProducer.java    From fresco with MIT License 5 votes vote down vote up
private int findFirstProducerForSize(int startIndex, ResizeOptions resizeOptions) {
  for (int i = startIndex; i < mThumbnailProducers.length; i++) {
    if (mThumbnailProducers[i].canProvideImageForSize(resizeOptions)) {
      return i;
    }
  }

  return -1;
}