Java Code Examples for com.facebook.imagepipeline.request.ImageRequest#getResizeOptions()

The following examples show how to use com.facebook.imagepipeline.request.ImageRequest#getResizeOptions() . 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: 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 2
Source File: DefaultCacheKeyFactory.java    From fresco with MIT License 6 votes vote down vote up
@Override
public CacheKey getPostprocessedBitmapCacheKey(
    ImageRequest request, @Nullable Object callerContext) {
  final Postprocessor postprocessor = request.getPostprocessor();
  final CacheKey postprocessorCacheKey;
  final String postprocessorName;
  if (postprocessor != null) {
    postprocessorCacheKey = postprocessor.getPostprocessorCacheKey();
    postprocessorName = postprocessor.getClass().getName();
  } else {
    postprocessorCacheKey = null;
    postprocessorName = null;
  }
  return new BitmapMemoryCacheKey(
      getCacheKeySourceUri(request.getSourceUri()).toString(),
      request.getResizeOptions(),
      request.getRotationOptions(),
      request.getImageDecodeOptions(),
      postprocessorCacheKey,
      postprocessorName,
      callerContext);
}
 
Example 3
Source File: DefaultCacheKeyFactory.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
@Override
public BitmapMemoryCacheKey getBitmapCacheKey(ImageRequest request) {
  return new BitmapMemoryCacheKey(
      getCacheKeySourceUri(request.getSourceUri()).toString(),
      request.getResizeOptions(),
      request.getAutoRotateEnabled(),
      request.getImageDecodeOptions());
}
 
Example 4
Source File: DefaultCacheKeyFactory.java    From fresco with MIT License 5 votes vote down vote up
@Override
public CacheKey getBitmapCacheKey(ImageRequest request, @Nullable Object callerContext) {
  return new BitmapMemoryCacheKey(
      getCacheKeySourceUri(request.getSourceUri()).toString(),
      request.getResizeOptions(),
      request.getRotationOptions(),
      request.getImageDecodeOptions(),
      null,
      null,
      callerContext);
}
 
Example 5
Source File: ImagePipeline.java    From fresco with MIT License 5 votes vote down vote up
/**
 * Submits a request for execution and returns a DataSource representing the pending encoded
 * image(s).
 *
 * <p>The ResizeOptions in the imageRequest will be ignored for this fetch
 *
 * <p>The returned DataSource must be closed once the client has finished with it.
 *
 * @param imageRequest the request to submit
 * @return a DataSource representing the pending encoded image(s)
 */
public DataSource<CloseableReference<PooledByteBuffer>> fetchEncodedImage(
    ImageRequest imageRequest, Object callerContext, @Nullable RequestListener requestListener) {
  Preconditions.checkNotNull(imageRequest.getSourceUri());
  try {
    Producer<CloseableReference<PooledByteBuffer>> producerSequence =
        mProducerSequenceFactory.getEncodedImageProducerSequence(imageRequest);
    // The resize options are used to determine whether images are going to be downsampled during
    // decode or not. For the case where the image has to be downsampled and it's a local image it
    // will be kept as a FileInputStream until decoding instead of reading it in memory. Since
    // this method returns an encoded image, it should always be read into memory. Therefore, the
    // resize options are ignored to avoid treating the image as if it was to be downsampled
    // during decode.
    if (imageRequest.getResizeOptions() != null) {
      imageRequest = ImageRequestBuilder.fromRequest(imageRequest).setResizeOptions(null).build();
    }
    return submitFetchRequest(
        producerSequence,
        imageRequest,
        ImageRequest.RequestLevel.FULL_FETCH,
        callerContext,
        requestListener,
        null);
  } catch (Exception exception) {
    return DataSources.immediateFailedDataSource(exception);
  }
}