Java 类com.facebook.imagepipeline.common.RotationOptions 实例源码

项目:GitHub    文件:ImageRequest.java   
protected ImageRequest(ImageRequestBuilder builder) {
  mCacheChoice = builder.getCacheChoice();
  mSourceUri = builder.getSourceUri();
  mSourceUriType = getSourceUriType(mSourceUri);
  mMediaVariations = builder.getMediaVariations();

  mProgressiveRenderingEnabled = builder.isProgressiveRenderingEnabled();
  mLocalThumbnailPreviewsEnabled = builder.isLocalThumbnailPreviewsEnabled();

  mImageDecodeOptions = builder.getImageDecodeOptions();

  mResizeOptions = builder.getResizeOptions();
  mRotationOptions = builder.getRotationOptions() == null
      ? RotationOptions.autoRotate() : builder.getRotationOptions();
  mBytesRange = builder.getBytesRange();

  mRequestPriority = builder.getRequestPriority();
  mLowestPermittedRequestLevel = builder.getLowestPermittedRequestLevel();
  mIsDiskCacheEnabled = builder.isDiskCacheEnabled();

  mPostprocessor = builder.getPostprocessor();

  mRequestListener = builder.getRequestListener();
}
项目:GitHub    文件:BitmapMemoryCacheKey.java   
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();
}
项目:GitHub    文件:ResizeAndRotateProducer.java   
/**
 * Get an inverted exif orientation (2, 4, 5, 7) but adjusted to take the force rotation angle
 * into consideration
 *
 * @throws IllegalArgumentException if encoded image passed doesn't have an inverted EXIF
 *     orientation
 */
private static int getForceRotatedInvertedExifOrientation(
    RotationOptions rotationOptions, EncodedImage encodedImage) {
  int exifOrientation = encodedImage.getExifOrientation();
  int index = INVERTED_EXIF_ORIENTATIONS.indexOf(exifOrientation);
  if (index < 0) {
    throw new IllegalArgumentException("Only accepts inverted exif orientations");
  }
  int forcedAngle = RotationOptions.NO_ROTATION;
  if (!rotationOptions.useImageMetadata()) {
    forcedAngle = rotationOptions.getForcedAngle();
  }
  int timesToRotate = forcedAngle / 90;
  return INVERTED_EXIF_ORIENTATIONS.get(
      (index + timesToRotate) % INVERTED_EXIF_ORIENTATIONS.size());
}
项目:GitHub    文件:ImageRequestTest.java   
@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)
      .setMediaVariations(MediaVariations.forMediaId("A113"))
      .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);
}
项目:GitHub    文件:ResizeAndRotateProducerTest.java   
@Test
public void testDoesNotTransformIfImageRotationAngleUnkown() {
  whenResizingEnabled();
  whenRequestSpecificRotation(RotationOptions.NO_ROTATION);

  provideIntermediateResult(
      DefaultImageFormats.JPEG,
      800,
      800,
      EncodedImage.UNKNOWN_ROTATION_ANGLE,
      ExifInterface.ORIENTATION_UNDEFINED);
  verifyIntermediateResultPassedThroughUnchanged();

  provideFinalResult(
      DefaultImageFormats.JPEG,
      800,
      800,
      EncodedImage.UNKNOWN_ROTATION_ANGLE,
      ExifInterface.ORIENTATION_UNDEFINED);
  verifyFinalResultPassedThroughUnchanged();
  verifyZeroJpegTranscoderInteractions();
}
项目:GitHub    文件:ResizeAndRotateProducerTest.java   
@Test
public void testDoesNotResizeIfJpegButResizingDisabled() throws Exception {
  whenResizingDisabled();
  final int preferredWidth = 300;
  final int preferredHeight = 600;
  whenRequestWidthAndHeight(preferredWidth, preferredHeight);
  whenRequestSpecificRotation(RotationOptions.NO_ROTATION);

  provideIntermediateResult(
      DefaultImageFormats.JPEG,
      preferredWidth * 2,
      preferredHeight * 2,
      0,
      ExifInterface.ORIENTATION_NORMAL);
  verifyIntermediateResultPassedThroughUnchanged();

  provideFinalResult(
      DefaultImageFormats.JPEG,
      preferredWidth * 2,
      preferredHeight * 2,
      0,
      ExifInterface.ORIENTATION_NORMAL);
  verifyFinalResultPassedThroughUnchanged();

  verifyZeroJpegTranscoderInteractions();
}
项目:GitHub    文件:PipelineUtil.java   
/**
 * Utility method which adds optional configuration to ImageRequest
 *
 * @param imageRequestBuilder The Builder for ImageRequest
 * @param config              The Config
 */
public static void addOptionalFeatures(ImageRequestBuilder imageRequestBuilder, Config config) {
  if (config.usePostprocessor) {
    final Postprocessor postprocessor;
    switch (config.postprocessorType) {
      case "use_slow_postprocessor":
        postprocessor = DelayPostprocessor.getMediumPostprocessor();
        break;
      case "use_fast_postprocessor":
        postprocessor = DelayPostprocessor.getFastPostprocessor();
        break;
      default:
        postprocessor = DelayPostprocessor.getMediumPostprocessor();
    }
    imageRequestBuilder.setPostprocessor(postprocessor);
  }
  if (config.rotateUsingMetaData) {
    imageRequestBuilder.setRotationOptions(RotationOptions.autoRotateAtRenderTime());
  } else {
    imageRequestBuilder
        .setRotationOptions(RotationOptions.forceRotation(config.forcedRotationAngle));
  }
}
项目:cardinalsSample    文件:FrescoManager.java   
public void display(SimpleDraweeView view, String url, Postprocessor postprocessor) {
    if (!TextUtils.isEmpty(url)) {
        Uri uri;
        if (URLUtil.isNetworkUrl(url)) {
            uri = Uri.parse(url);
        } else {
            uri = Uri.fromFile(new File(url));
        }
        ImageRequest request = ImageRequestBuilder
                .newBuilderWithSource(uri)
                .setPostprocessor(postprocessor)
                .setProgressiveRenderingEnabled(true)
                //.setResizeOptions(new ResizeOptions(100, 100))
                .setLocalThumbnailPreviewsEnabled(true)
                .setRotationOptions(RotationOptions.autoRotateAtRenderTime())
                .build();

        controller = Fresco.newDraweeControllerBuilder()
                .setImageRequest(request)
                .setOldController(view.getController())
                .build();
        view.setController(controller);

    }

}
项目:Watermark    文件:FrescoImageLoader.java   
public static void setImageSmall(String url,
                                 SimpleDraweeView simpleDraweeView,
                                 int width,
                                 int height,
                                 SquareRelativeLayout relativeLayout, boolean playGif) {

    Uri uri = Uri.parse(url);
    ImageRequest request = ImageRequestBuilder
            .newBuilderWithSource(uri)
            .setRotationOptions(RotationOptions.autoRotate())
            .setResizeOptions(new ResizeOptions(width, height))
            .setLowestPermittedRequestLevel(ImageRequest.RequestLevel.FULL_FETCH)
            .build();
    DraweeController controller = Fresco.newDraweeControllerBuilder()
            .setTapToRetryEnabled(true)
            .setImageRequest(request)
            .setAutoPlayAnimations(playGif)
            .setOldController(simpleDraweeView.getController())
            .build();
    relativeLayout.setLayoutParams(new RelativeLayout.LayoutParams(width - 5, height));
    simpleDraweeView.setController(controller);
}
项目:fresco    文件:ImageRequest.java   
protected ImageRequest(ImageRequestBuilder builder) {
  mCacheChoice = builder.getCacheChoice();
  mSourceUri = builder.getSourceUri();
  mSourceUriType = getSourceUriType(mSourceUri);
  mMediaVariations = builder.getMediaVariations();

  mProgressiveRenderingEnabled = builder.isProgressiveRenderingEnabled();
  mLocalThumbnailPreviewsEnabled = builder.isLocalThumbnailPreviewsEnabled();

  mImageDecodeOptions = builder.getImageDecodeOptions();

  mResizeOptions = builder.getResizeOptions();
  mRotationOptions = builder.getRotationOptions() == null
      ? RotationOptions.autoRotate() : builder.getRotationOptions();
  mBytesRange = builder.getBytesRange();

  mRequestPriority = builder.getRequestPriority();
  mLowestPermittedRequestLevel = builder.getLowestPermittedRequestLevel();
  mIsDiskCacheEnabled = builder.isDiskCacheEnabled();

  mPostprocessor = builder.getPostprocessor();

  mRequestListener = builder.getRequestListener();
}
项目:fresco    文件:BitmapMemoryCacheKey.java   
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();
}
项目:fresco    文件:ResizeAndRotateProducer.java   
/**
 * Get an inverted exif orientation (2, 4, 5, 7) but adjusted to take the force rotation angle
 * into consideration
 *
 * @throws IllegalArgumentException if encoded image passed doesn't have an inverted EXIF
 *     orientation
 */
private static int getForceRotatedInvertedExifOrientation(
    RotationOptions rotationOptions, EncodedImage encodedImage) {
  int exifOrientation = encodedImage.getExifOrientation();
  int index = INVERTED_EXIF_ORIENTATIONS.indexOf(exifOrientation);
  if (index < 0) {
    throw new IllegalArgumentException("Only accepts inverted exif orientations");
  }
  int forcedAngle = RotationOptions.NO_ROTATION;
  if (!rotationOptions.useImageMetadata()) {
    forcedAngle = rotationOptions.getForcedAngle();
  }
  int timesToRotate = forcedAngle / 90;
  return INVERTED_EXIF_ORIENTATIONS.get(
      (index + timesToRotate) % INVERTED_EXIF_ORIENTATIONS.size());
}
项目:fresco    文件:ImageRequestTest.java   
@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)
      .setMediaVariations(MediaVariations.forMediaId("A113"))
      .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);
}
项目:fresco    文件:ResizeAndRotateProducerTest.java   
@Test
public void testDoesNotTransformIfImageRotationAngleUnkown() {
  whenResizingEnabled();
  whenRequestSpecificRotation(RotationOptions.NO_ROTATION);

  provideIntermediateResult(
      DefaultImageFormats.JPEG,
      800,
      800,
      EncodedImage.UNKNOWN_ROTATION_ANGLE,
      ExifInterface.ORIENTATION_UNDEFINED);
  verifyIntermediateResultPassedThroughUnchanged();

  provideFinalResult(
      DefaultImageFormats.JPEG,
      800,
      800,
      EncodedImage.UNKNOWN_ROTATION_ANGLE,
      ExifInterface.ORIENTATION_UNDEFINED);
  verifyFinalResultPassedThroughUnchanged();
  verifyZeroJpegTranscoderInteractions();
}
项目:fresco    文件:ResizeAndRotateProducerTest.java   
@Test
public void testDoesNotResizeIfJpegButResizingDisabled() throws Exception {
  whenResizingDisabled();
  final int preferredWidth = 300;
  final int preferredHeight = 600;
  whenRequestWidthAndHeight(preferredWidth, preferredHeight);
  whenRequestSpecificRotation(RotationOptions.NO_ROTATION);

  provideIntermediateResult(
      DefaultImageFormats.JPEG,
      preferredWidth * 2,
      preferredHeight * 2,
      0,
      ExifInterface.ORIENTATION_NORMAL);
  verifyIntermediateResultPassedThroughUnchanged();

  provideFinalResult(
      DefaultImageFormats.JPEG,
      preferredWidth * 2,
      preferredHeight * 2,
      0,
      ExifInterface.ORIENTATION_NORMAL);
  verifyFinalResultPassedThroughUnchanged();

  verifyZeroJpegTranscoderInteractions();
}
项目:fresco    文件:PipelineUtil.java   
/**
 * Utility method which adds optional configuration to ImageRequest
 *
 * @param imageRequestBuilder The Builder for ImageRequest
 * @param config              The Config
 */
public static void addOptionalFeatures(ImageRequestBuilder imageRequestBuilder, Config config) {
  if (config.usePostprocessor) {
    final Postprocessor postprocessor;
    switch (config.postprocessorType) {
      case "use_slow_postprocessor":
        postprocessor = DelayPostprocessor.getMediumPostprocessor();
        break;
      case "use_fast_postprocessor":
        postprocessor = DelayPostprocessor.getFastPostprocessor();
        break;
      default:
        postprocessor = DelayPostprocessor.getMediumPostprocessor();
    }
    imageRequestBuilder.setPostprocessor(postprocessor);
  }
  if (config.rotateUsingMetaData) {
    imageRequestBuilder.setRotationOptions(RotationOptions.autoRotateAtRenderTime());
  } else {
    imageRequestBuilder
        .setRotationOptions(RotationOptions.forceRotation(config.forcedRotationAngle));
  }
}
项目:GitHub    文件:PipelineDraweeControllerBuilder.java   
@Override
public PipelineDraweeControllerBuilder setUri(@Nullable Uri uri) {
  if (uri == null) {
    return super.setImageRequest(null);
  }
  ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(uri)
      .setRotationOptions(RotationOptions.autoRotateAtRenderTime())
      .build();
  return super.setImageRequest(imageRequest);
}
项目:GitHub    文件:ImageRequestBuilder.java   
/**
 * Enables or disables auto-rotate for the image in case image has orientation.
 * @return the updated builder instance
 * @param enabled
 * @deprecated Use #setRotationOptions(RotationOptions)
 */
@Deprecated
public ImageRequestBuilder setAutoRotateEnabled(boolean enabled) {
  if (enabled) {
    return setRotationOptions(RotationOptions.autoRotate());
  } else {
    return setRotationOptions(RotationOptions.disableRotation());
  }
}
项目:GitHub    文件:ResizeAndRotateProducer.java   
private static int getRotationAngle(RotationOptions rotationOptions, EncodedImage encodedImage) {
  if (!rotationOptions.rotationEnabled()) {
    return RotationOptions.NO_ROTATION;
  }
  int rotationFromMetadata = extractOrientationFromMetadata(encodedImage);
  if (rotationOptions.useImageMetadata()) {
    return rotationFromMetadata;
  }
  return (rotationFromMetadata + rotationOptions.getForcedAngle()) % FULL_ROUND;
}
项目:GitHub    文件:ResizeAndRotateProducer.java   
private static int extractOrientationFromMetadata(EncodedImage encodedImage) {
  switch (encodedImage.getRotationAngle()) {
    case RotationOptions.ROTATE_90:
    case RotationOptions.ROTATE_180:
    case RotationOptions.ROTATE_270:
      return encodedImage.getRotationAngle();
    default:
      return 0;
  }
}
项目:GitHub    文件:ResizeAndRotateProducer.java   
private static boolean shouldRotateUsingExifOrientation(
    RotationOptions rotationOptions, EncodedImage encodedImage) {
  if (!rotationOptions.rotationEnabled() || rotationOptions.canDeferUntilRendered()) {
    encodedImage.setExifOrientation(ExifInterface.ORIENTATION_UNDEFINED);
    return false;
  }
  return INVERTED_EXIF_ORIENTATIONS.contains(encodedImage.getExifOrientation());
}
项目:GitHub    文件:DownsampleUtilTest.java   
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));
}
项目:GitHub    文件:DownsampleUtilTest.java   
private void whenRequestResizeWidthHeightAndMaxBitmapSize(
    int width,
    int height,
    float maxBitmapSize) {
  when(mImageRequest.getPreferredWidth()).thenReturn(width);
  when(mImageRequest.getPreferredHeight()).thenReturn(height);
  when(mImageRequest.getResizeOptions()).thenReturn(
      new ResizeOptions(width, height, maxBitmapSize));
  when(mImageRequest.getRotationOptions()).thenReturn(RotationOptions.disableRotation());
}
项目:GitHub    文件:ResizeAndRotateProducerTest.java   
@Test
public void testDoesNotTransformIfMetadataAngleAndRequestedRotationHaveOppositeValues() {
  whenResizingEnabled();
  whenRequestSpecificRotation(RotationOptions.ROTATE_270);

  provideFinalResult(DefaultImageFormats.JPEG, 400, 200, 90, ExifInterface.ORIENTATION_ROTATE_90);
  verifyAFinalResultPassedThroughNotResized();
  verifyZeroJpegTranscoderInteractions();
}
项目:GitHub    文件:ResizeAndRotateProducerTest.java   
@Test
public void testDoesResizeIfJpegAndResizingEnabled() throws Exception {
  whenResizingEnabled();
  final int preferredWidth = 300;
  final int preferredHeight = 600;
  whenRequestWidthAndHeight(preferredWidth, preferredHeight);
  whenRequestSpecificRotation(RotationOptions.NO_ROTATION);

  provideIntermediateResult(
      DefaultImageFormats.JPEG,
      preferredWidth * 2,
      preferredHeight * 2,
      0,
      ExifInterface.ORIENTATION_NORMAL);
  verifyNoIntermediateResultPassedThrough();

  provideFinalResult(
      DefaultImageFormats.JPEG,
      preferredWidth * 2,
      preferredHeight * 2,
      0,
      ExifInterface.ORIENTATION_NORMAL);
  verifyAFinalResultPassedThroughResized();

  assertEquals(2, mFinalResult.getUnderlyingReferenceTestOnly().getRefCountTestOnly());
  assertTrue(mPooledByteBuffer.isClosed());

  verifyJpegTranscoderInteractions(4, 0);
}
项目:GitHub    文件:ResizeAndRotateProducerTest.java   
@Test
public void testDoesNotUpscale() {
  whenResizingEnabled();
  whenRequestWidthAndHeight(150, 150);
  whenRequestSpecificRotation(RotationOptions.NO_ROTATION);

  provideFinalResult(DefaultImageFormats.JPEG, 100, 100, 0, ExifInterface.ORIENTATION_NORMAL);
  verifyFinalResultPassedThroughUnchanged();
  verifyZeroJpegTranscoderInteractions();
}
项目:GitHub    文件:ResizeAndRotateProducerTest.java   
@Test
public void testDoesRotateWhenSpecificRotationRequested() {
  whenResizingEnabled();
  whenRequestWidthAndHeight(200, 400);
  whenRequestSpecificRotation(RotationOptions.ROTATE_270);

  provideFinalResult(DefaultImageFormats.JPEG, 400, 200, 0, ExifInterface.ORIENTATION_UNDEFINED);
  verifyAFinalResultPassedThroughNotResized();
  verifyJpegTranscoderInteractions(8, 270);
}
项目:GitHub    文件:DraweeRotationFragment.java   
private void setRotationOptions(RotationOptions rotationOptions) {
  ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(mUri)
      .setRotationOptions(rotationOptions)
      .build();
  mSimpleDraweeView.setController(
      Fresco.newDraweeControllerBuilder().setImageRequest(imageRequest).build());
}
项目:cardinalsSample    文件:FrescoManager.java   
/**
 * @param view View
 * @param url  网络路径或者本地路径
 */

public void display(SimpleDraweeView view, String url) {
    if (!TextUtils.isEmpty(url)) {
        Uri uri;
        if (URLUtil.isNetworkUrl(url)) {
            uri = Uri.parse(url);
        } else {
            uri = Uri.fromFile(new File(url));
        }
        ImageRequest request = ImageRequestBuilder
                .newBuilderWithSource(uri)
                .setProgressiveRenderingEnabled(true)
                .setLocalThumbnailPreviewsEnabled(true)
                .setRotationOptions(RotationOptions.autoRotateAtRenderTime())
                .build();

        controller = Fresco.newDraweeControllerBuilder()
                .setImageRequest(request)
                .setTapToRetryEnabled(true)
                .setOldController(view.getController())
                .build();
        view.setController(controller);

    }

}
项目:react-native-udesk    文件:UdeskUtil.java   
public static void loadFileFromSdcard(final Context context, final SimpleDraweeView draweeView, Uri loackUri, final int reqWidth, final int reqHeight) {
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(loackUri)
            .setRotationOptions(RotationOptions.autoRotate())
            .setLocalThumbnailPreviewsEnabled(true)
            .setResizeOptions(new ResizeOptions(dip2px(context, 140), dip2px(context, 220)))
            .build();
    DraweeController controller = Fresco.newDraweeControllerBuilder()
            .setImageRequest(request)
            .setOldController(draweeView.getController())
            .setTapToRetryEnabled(true)
            .setControllerListener(new BaseControllerListener<ImageInfo>() {
                @Override
                public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable anim) {
                    if (imageInfo == null) {
                        return;
                    }

                    ViewGroup.LayoutParams layoutParams = draweeView.getLayoutParams();
                    int width = reqWidth;
                    int height = reqHeight;
                    int imgWidth = dip2px(context, 140);
                    int imgHight = dip2px(context, 220);
                    int bitScalew = getRatioSize(width, height, imgHight, imgWidth);
                    layoutParams.height = height / bitScalew;
                    layoutParams.width = width / bitScalew;
                    draweeView.requestLayout();
                }
            })
            .setAutoPlayAnimations(true)
            .build();
    draweeView.setController(controller);
}
项目:JianshuApp    文件:UniversalDraweeView.java   
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()));
    }
}
项目:fresco    文件:PipelineDraweeControllerBuilder.java   
@Override
public PipelineDraweeControllerBuilder setUri(@Nullable Uri uri) {
  if (uri == null) {
    return super.setImageRequest(null);
  }
  ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(uri)
      .setRotationOptions(RotationOptions.autoRotateAtRenderTime())
      .build();
  return super.setImageRequest(imageRequest);
}
项目:fresco    文件:ImageRequestBuilder.java   
/**
 * Enables or disables auto-rotate for the image in case image has orientation.
 * @return the updated builder instance
 * @param enabled
 * @deprecated Use #setRotationOptions(RotationOptions)
 */
@Deprecated
public ImageRequestBuilder setAutoRotateEnabled(boolean enabled) {
  if (enabled) {
    return setRotationOptions(RotationOptions.autoRotate());
  } else {
    return setRotationOptions(RotationOptions.disableRotation());
  }
}
项目:fresco    文件:ResizeAndRotateProducer.java   
private static int getRotationAngle(RotationOptions rotationOptions, EncodedImage encodedImage) {
  if (!rotationOptions.rotationEnabled()) {
    return RotationOptions.NO_ROTATION;
  }
  int rotationFromMetadata = extractOrientationFromMetadata(encodedImage);
  if (rotationOptions.useImageMetadata()) {
    return rotationFromMetadata;
  }
  return (rotationFromMetadata + rotationOptions.getForcedAngle()) % FULL_ROUND;
}
项目:fresco    文件:ResizeAndRotateProducer.java   
private static int extractOrientationFromMetadata(EncodedImage encodedImage) {
  switch (encodedImage.getRotationAngle()) {
    case RotationOptions.ROTATE_90:
    case RotationOptions.ROTATE_180:
    case RotationOptions.ROTATE_270:
      return encodedImage.getRotationAngle();
    default:
      return 0;
  }
}
项目:fresco    文件:ResizeAndRotateProducer.java   
private static boolean shouldRotateUsingExifOrientation(
    RotationOptions rotationOptions, EncodedImage encodedImage) {
  if (!rotationOptions.rotationEnabled() || rotationOptions.canDeferUntilRendered()) {
    encodedImage.setExifOrientation(ExifInterface.ORIENTATION_UNDEFINED);
    return false;
  }
  return INVERTED_EXIF_ORIENTATIONS.contains(encodedImage.getExifOrientation());
}
项目:fresco    文件:DownsampleUtilTest.java   
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));
}
项目:fresco    文件:DownsampleUtilTest.java   
private void whenRequestResizeWidthHeightAndMaxBitmapSize(
    int width,
    int height,
    float maxBitmapSize) {
  when(mImageRequest.getPreferredWidth()).thenReturn(width);
  when(mImageRequest.getPreferredHeight()).thenReturn(height);
  when(mImageRequest.getResizeOptions()).thenReturn(
      new ResizeOptions(width, height, maxBitmapSize));
  when(mImageRequest.getRotationOptions()).thenReturn(RotationOptions.disableRotation());
}
项目:fresco    文件:ResizeAndRotateProducerTest.java   
@Test
public void testDoesNotTransformIfMetadataAngleAndRequestedRotationHaveOppositeValues() {
  whenResizingEnabled();
  whenRequestSpecificRotation(RotationOptions.ROTATE_270);

  provideFinalResult(DefaultImageFormats.JPEG, 400, 200, 90, ExifInterface.ORIENTATION_ROTATE_90);
  verifyAFinalResultPassedThroughNotResized();
  verifyZeroJpegTranscoderInteractions();
}
项目:fresco    文件:ResizeAndRotateProducerTest.java   
@Test
public void testDoesResizeIfJpegAndResizingEnabled() throws Exception {
  whenResizingEnabled();
  final int preferredWidth = 300;
  final int preferredHeight = 600;
  whenRequestWidthAndHeight(preferredWidth, preferredHeight);
  whenRequestSpecificRotation(RotationOptions.NO_ROTATION);

  provideIntermediateResult(
      DefaultImageFormats.JPEG,
      preferredWidth * 2,
      preferredHeight * 2,
      0,
      ExifInterface.ORIENTATION_NORMAL);
  verifyNoIntermediateResultPassedThrough();

  provideFinalResult(
      DefaultImageFormats.JPEG,
      preferredWidth * 2,
      preferredHeight * 2,
      0,
      ExifInterface.ORIENTATION_NORMAL);
  verifyAFinalResultPassedThroughResized();

  assertEquals(2, mFinalResult.getUnderlyingReferenceTestOnly().getRefCountTestOnly());
  assertTrue(mPooledByteBuffer.isClosed());

  verifyJpegTranscoderInteractions(4, 0);
}