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

项目:GitHub    文件:ImageFormatOverrideExample.java   
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
  SimpleDraweeView simpleDraweeView = (SimpleDraweeView) view.findViewById(R.id.drawee_view);

  ImageDecodeOptions imageDecodeOptionsWithCustomDecoder = new ImageDecodeOptionsBuilder()
      .setCustomImageDecoder(CUSTOM_COLOR_DECODER)
      .build();

  AbstractDraweeController controller = Fresco.newDraweeControllerBuilder()
      .setImageRequest(
          ImageRequestBuilder.newBuilderWithResourceId(R.raw.custom_color1)
              .setImageDecodeOptions(imageDecodeOptionsWithCustomDecoder)
              .build())
      .build();
  simpleDraweeView.setController(controller);
}
项目:GitHub    文件:AnimatedImageFactoryImpl.java   
/**
 * Decodes a GIF into a CloseableImage.
 * @param encodedImage encoded image (native byte array holding the encoded bytes and meta data)
 * @param options the options for the decode
 * @param bitmapConfig the Bitmap.Config used to generate the output bitmaps
 * @return a {@link CloseableImage} for the GIF image
 */
public CloseableImage decodeGif(
    final EncodedImage encodedImage,
    final ImageDecodeOptions options,
    final Bitmap.Config bitmapConfig) {
  if (sGifAnimatedImageDecoder == null) {
    throw new UnsupportedOperationException("To encode animated gif please add the dependency " +
        "to the animated-gif module");
  }
  final CloseableReference<PooledByteBuffer> bytesRef = encodedImage.getByteBufferRef();
  Preconditions.checkNotNull(bytesRef);
  try {
    final PooledByteBuffer input = bytesRef.get();
    AnimatedImage gifImage = sGifAnimatedImageDecoder.decode(input.getNativePtr(), input.size());

    return getCloseableImage(options, gifImage, bitmapConfig);
  } finally {
    CloseableReference.closeSafely(bytesRef);
  }
}
项目:GitHub    文件:AnimatedImageFactoryImpl.java   
/**
 * Decode a WebP into a CloseableImage.
 * @param encodedImage encoded image (native byte array holding the encoded bytes and meta data)
 * @param options the options for the decode
 * @param bitmapConfig the Bitmap.Config used to generate the output bitmaps
 * @return a {@link CloseableImage} for the WebP image
 */
public CloseableImage decodeWebP(
    final EncodedImage encodedImage,
    final ImageDecodeOptions options,
    final Bitmap.Config bitmapConfig) {
  if (sWebpAnimatedImageDecoder == null) {
    throw new UnsupportedOperationException("To encode animated webp please add the dependency " +
        "to the animated-webp module");
  }
  final CloseableReference<PooledByteBuffer> bytesRef = encodedImage.getByteBufferRef();
  Preconditions.checkNotNull(bytesRef);
  try {
    final PooledByteBuffer input = bytesRef.get();
    AnimatedImage webPImage = sWebpAnimatedImageDecoder.decode(
        input.getNativePtr(),
        input.size());
    return getCloseableImage(options, webPImage, bitmapConfig);
  } finally {
    CloseableReference.closeSafely(bytesRef);
  }
}
项目: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    文件:DefaultImageDecoder.java   
@Override
public CloseableImage decode(
    EncodedImage encodedImage,
    int length,
    QualityInfo qualityInfo,
    ImageDecodeOptions options) {
  ImageFormat imageFormat = encodedImage.getImageFormat();
  if (imageFormat == DefaultImageFormats.JPEG) {
    return decodeJpeg(encodedImage, length, qualityInfo, options);
  } else if (imageFormat == DefaultImageFormats.GIF) {
    return decodeGif(encodedImage, length, qualityInfo, options);
  } else if (imageFormat == DefaultImageFormats.WEBP_ANIMATED) {
    return decodeAnimatedWebp(encodedImage, length, qualityInfo, options);
  } else if (imageFormat == ImageFormat.UNKNOWN) {
    throw new DecodeException("unknown image format", encodedImage);
  }
  return decodeStaticImage(encodedImage, options);
}
项目:GitHub    文件:DefaultImageDecoder.java   
/**
 * Decodes image.
 *
 * @param encodedImage input image (encoded bytes plus meta data)
 * @param length if image type supports decoding incomplete image then determines where the image
 *     data should be cut for decoding.
 * @param qualityInfo quality information for the image
 * @param options options that cange decode behavior
 */
@Override
public CloseableImage decode(
    final EncodedImage encodedImage,
    final int length,
    final QualityInfo qualityInfo,
    final ImageDecodeOptions options) {
  if (options.customImageDecoder != null) {
    return options.customImageDecoder.decode(encodedImage, length, qualityInfo, options);
  }
  ImageFormat imageFormat = encodedImage.getImageFormat();
  if (imageFormat == null || imageFormat == ImageFormat.UNKNOWN) {
    imageFormat = ImageFormatChecker.getImageFormat_WrapIOException(
        encodedImage.getInputStream());
    encodedImage.setImageFormat(imageFormat);
  }
  if (mCustomDecoders != null) {
    ImageDecoder decoder = mCustomDecoders.get(imageFormat);
    if (decoder != null) {
      return decoder.decode(encodedImage, length, qualityInfo, options);
    }
  }
  return mDefaultDecoder.decode(encodedImage, length, qualityInfo, options);
}
项目:GitHub    文件:DefaultImageDecoder.java   
/**
 * Decodes gif into CloseableImage.
 *
 * @param encodedImage input image (encoded bytes plus meta data)
 * @return a CloseableImage
 */
public CloseableImage decodeGif(
    final EncodedImage encodedImage,
    final int length,
    final QualityInfo qualityInfo,
    final ImageDecodeOptions options) {
  InputStream is = encodedImage.getInputStream();
  if (is == null) {
    return null;
  }
  try {
    if (!options.forceStaticImage
        && mAnimatedGifDecoder != null) {
      return mAnimatedGifDecoder.decode(encodedImage, length, qualityInfo, options);
    }
    return decodeStaticImage(encodedImage, options);
  } finally {
    Closeables.closeQuietly(is);
  }
}
项目:GitHub    文件:DefaultImageDecoder.java   
/**
 * @param encodedImage input image (encoded bytes plus meta data)
 * @return a CloseableStaticBitmap
 */
public CloseableStaticBitmap decodeStaticImage(
    final EncodedImage encodedImage,
    ImageDecodeOptions options) {
  CloseableReference<Bitmap> bitmapReference =
      mPlatformDecoder.decodeFromEncodedImage(encodedImage, options.bitmapConfig, null);
  try {
    return new CloseableStaticBitmap(
        bitmapReference,
        ImmutableQualityInfo.FULL_QUALITY,
        encodedImage.getRotationAngle(),
        encodedImage.getExifOrientation());
  } finally {
    bitmapReference.close();
  }
}
项目:GitHub    文件:DefaultImageDecoder.java   
/**
 * Decodes a partial jpeg.
 *
 * @param encodedImage input image (encoded bytes plus meta data)
 * @param length amount of currently available data in bytes
 * @param qualityInfo quality info for the image
 * @return a CloseableStaticBitmap
 */
public CloseableStaticBitmap decodeJpeg(
    final EncodedImage encodedImage,
    int length,
    QualityInfo qualityInfo,
    ImageDecodeOptions options) {
  CloseableReference<Bitmap> bitmapReference =
      mPlatformDecoder.decodeJPEGFromEncodedImage(
          encodedImage, options.bitmapConfig, null, length);
  try {
    return new CloseableStaticBitmap(
        bitmapReference,
        qualityInfo,
        encodedImage.getRotationAngle(),
        encodedImage.getExifOrientation());
  } finally {
    bitmapReference.close();
  }
}
项目:GitHub    文件:KeyframesDecoderExample.java   
@Override
public CloseableImage decode(
    EncodedImage encodedImage,
    int length,
    QualityInfo qualityInfo,
    ImageDecodeOptions options) {
  InputStream encodedInputStream = null;
  try {
    encodedInputStream = encodedImage.getInputStream();
    return new CloseableKeyframesImage(
        KFImageDeserializer.deserialize(encodedInputStream));
  } catch (IOException e) {
    e.printStackTrace();
    return null;
  } finally {
    Closeables.closeQuietly(encodedInputStream);
  }
}
项目:fresco    文件:AnimatedImageFactoryImpl.java   
/**
 * Decodes a GIF into a CloseableImage.
 * @param encodedImage encoded image (native byte array holding the encoded bytes and meta data)
 * @param options the options for the decode
 * @param bitmapConfig the Bitmap.Config used to generate the output bitmaps
 * @return a {@link CloseableImage} for the GIF image
 */
public CloseableImage decodeGif(
    final EncodedImage encodedImage,
    final ImageDecodeOptions options,
    final Bitmap.Config bitmapConfig) {
  if (sGifAnimatedImageDecoder == null) {
    throw new UnsupportedOperationException("To encode animated gif please add the dependency " +
        "to the animated-gif module");
  }
  final CloseableReference<PooledByteBuffer> bytesRef = encodedImage.getByteBufferRef();
  Preconditions.checkNotNull(bytesRef);
  try {
    final PooledByteBuffer input = bytesRef.get();
    AnimatedImage gifImage = sGifAnimatedImageDecoder.decode(input.getNativePtr(), input.size());

    return getCloseableImage(options, gifImage, bitmapConfig);
  } finally {
    CloseableReference.closeSafely(bytesRef);
  }
}
项目:fresco    文件:AnimatedImageFactoryImpl.java   
/**
 * Decode a WebP into a CloseableImage.
 * @param encodedImage encoded image (native byte array holding the encoded bytes and meta data)
 * @param options the options for the decode
 * @param bitmapConfig the Bitmap.Config used to generate the output bitmaps
 * @return a {@link CloseableImage} for the WebP image
 */
public CloseableImage decodeWebP(
    final EncodedImage encodedImage,
    final ImageDecodeOptions options,
    final Bitmap.Config bitmapConfig) {
  if (sWebpAnimatedImageDecoder == null) {
    throw new UnsupportedOperationException("To encode animated webp please add the dependency " +
        "to the animated-webp module");
  }
  final CloseableReference<PooledByteBuffer> bytesRef = encodedImage.getByteBufferRef();
  Preconditions.checkNotNull(bytesRef);
  try {
    final PooledByteBuffer input = bytesRef.get();
    AnimatedImage webPImage = sWebpAnimatedImageDecoder.decode(
        input.getNativePtr(),
        input.size());
    return getCloseableImage(options, webPImage, bitmapConfig);
  } finally {
    CloseableReference.closeSafely(bytesRef);
  }
}
项目: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    文件:DefaultImageDecoder.java   
@Override
public CloseableImage decode(
    EncodedImage encodedImage,
    int length,
    QualityInfo qualityInfo,
    ImageDecodeOptions options) {
  ImageFormat imageFormat = encodedImage.getImageFormat();
  if (imageFormat == DefaultImageFormats.JPEG) {
    return decodeJpeg(encodedImage, length, qualityInfo, options);
  } else if (imageFormat == DefaultImageFormats.GIF) {
    return decodeGif(encodedImage, length, qualityInfo, options);
  } else if (imageFormat == DefaultImageFormats.WEBP_ANIMATED) {
    return decodeAnimatedWebp(encodedImage, length, qualityInfo, options);
  } else if (imageFormat == ImageFormat.UNKNOWN) {
    throw new DecodeException("unknown image format", encodedImage);
  }
  return decodeStaticImage(encodedImage, options);
}
项目:fresco    文件:DefaultImageDecoder.java   
/**
 * Decodes image.
 *
 * @param encodedImage input image (encoded bytes plus meta data)
 * @param length if image type supports decoding incomplete image then determines where the image
 *     data should be cut for decoding.
 * @param qualityInfo quality information for the image
 * @param options options that cange decode behavior
 */
@Override
public CloseableImage decode(
    final EncodedImage encodedImage,
    final int length,
    final QualityInfo qualityInfo,
    final ImageDecodeOptions options) {
  if (options.customImageDecoder != null) {
    return options.customImageDecoder.decode(encodedImage, length, qualityInfo, options);
  }
  ImageFormat imageFormat = encodedImage.getImageFormat();
  if (imageFormat == null || imageFormat == ImageFormat.UNKNOWN) {
    imageFormat = ImageFormatChecker.getImageFormat_WrapIOException(
        encodedImage.getInputStream());
    encodedImage.setImageFormat(imageFormat);
  }
  if (mCustomDecoders != null) {
    ImageDecoder decoder = mCustomDecoders.get(imageFormat);
    if (decoder != null) {
      return decoder.decode(encodedImage, length, qualityInfo, options);
    }
  }
  return mDefaultDecoder.decode(encodedImage, length, qualityInfo, options);
}
项目:fresco    文件:DefaultImageDecoder.java   
/**
 * @param encodedImage input image (encoded bytes plus meta data)
 * @return a CloseableStaticBitmap
 */
public CloseableStaticBitmap decodeStaticImage(
    final EncodedImage encodedImage,
    ImageDecodeOptions options) {
  CloseableReference<Bitmap> bitmapReference =
      mPlatformDecoder.decodeFromEncodedImage(encodedImage, options.bitmapConfig, null);
  try {
    return new CloseableStaticBitmap(
        bitmapReference,
        ImmutableQualityInfo.FULL_QUALITY,
        encodedImage.getRotationAngle(),
        encodedImage.getExifOrientation());
  } finally {
    bitmapReference.close();
  }
}
项目:fresco    文件:DefaultImageDecoder.java   
/**
 * Decodes a partial jpeg.
 *
 * @param encodedImage input image (encoded bytes plus meta data)
 * @param length amount of currently available data in bytes
 * @param qualityInfo quality info for the image
 * @return a CloseableStaticBitmap
 */
public CloseableStaticBitmap decodeJpeg(
    final EncodedImage encodedImage,
    int length,
    QualityInfo qualityInfo,
    ImageDecodeOptions options) {
  CloseableReference<Bitmap> bitmapReference =
      mPlatformDecoder.decodeJPEGFromEncodedImage(
          encodedImage, options.bitmapConfig, null, length);
  try {
    return new CloseableStaticBitmap(
        bitmapReference,
        qualityInfo,
        encodedImage.getRotationAngle(),
        encodedImage.getExifOrientation());
  } finally {
    bitmapReference.close();
  }
}
项目:fresco    文件:KeyframesDecoderExample.java   
@Override
public CloseableImage decode(
    EncodedImage encodedImage,
    int length,
    QualityInfo qualityInfo,
    ImageDecodeOptions options) {
  InputStream encodedInputStream = null;
  try {
    encodedInputStream = encodedImage.getInputStream();
    return new CloseableKeyframesImage(
        KFImageDeserializer.deserialize(encodedInputStream));
  } catch (IOException e) {
    e.printStackTrace();
    return null;
  } finally {
    Closeables.closeQuietly(encodedInputStream);
  }
}
项目:fresco    文件:ImageFormatOverrideExample.java   
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
  SimpleDraweeView simpleDraweeView = (SimpleDraweeView) view.findViewById(R.id.drawee_view);

  ImageDecodeOptions imageDecodeOptionsWithCustomDecoder = new ImageDecodeOptionsBuilder()
      .setCustomImageDecoder(CUSTOM_COLOR_DECODER)
      .build();

  AbstractDraweeController controller = Fresco.newDraweeControllerBuilder()
      .setImageRequest(
          ImageRequestBuilder.newBuilderWithResourceId(R.raw.custom_color1)
              .setImageDecodeOptions(imageDecodeOptionsWithCustomDecoder)
              .build())
      .build();
  simpleDraweeView.setController(controller);
}
项目:GitHub    文件:AnimatedFactoryV2Impl.java   
@Override
public ImageDecoder getGifDecoder(final Bitmap.Config bitmapConfig) {
  return new ImageDecoder() {
    @Override
    public CloseableImage decode(
        EncodedImage encodedImage,
        int length,
        QualityInfo qualityInfo,
        ImageDecodeOptions options) {
      return getAnimatedImageFactory().decodeGif(encodedImage, options, bitmapConfig);
    }
  };
}
项目:GitHub    文件:AnimatedFactoryV2Impl.java   
@Override
public ImageDecoder getWebPDecoder(final Bitmap.Config bitmapConfig) {
  return new ImageDecoder() {
    @Override
    public CloseableImage decode(
        EncodedImage encodedImage,
        int length,
        QualityInfo qualityInfo,
        ImageDecodeOptions options) {
      return getAnimatedImageFactory().decodeWebP(encodedImage, options, bitmapConfig);
    }
  };
}
项目:GitHub    文件:AnimatedImageFactoryImpl.java   
private CloseableImage getCloseableImage(
    ImageDecodeOptions options,
    AnimatedImage image,
    Bitmap.Config bitmapConfig) {
  List<CloseableReference<Bitmap>> decodedFrames = null;
  CloseableReference<Bitmap> previewBitmap = null;
  try {
    final int frameForPreview = options.useLastFrameForPreview ? image.getFrameCount() - 1 : 0;
    if (options.forceStaticImage) {
      return new CloseableStaticBitmap(
          createPreviewBitmap(image, bitmapConfig, frameForPreview),
          ImmutableQualityInfo.FULL_QUALITY,
          0);
    }

    if (options.decodeAllFrames) {
      decodedFrames = decodeAllFrames(image, bitmapConfig);
      previewBitmap = CloseableReference.cloneOrNull(decodedFrames.get(frameForPreview));
    }

    if (options.decodePreviewFrame && previewBitmap == null) {
      previewBitmap = createPreviewBitmap(image, bitmapConfig, frameForPreview);
    }
    AnimatedImageResult animatedImageResult = AnimatedImageResult.newBuilder(image)
        .setPreviewBitmap(previewBitmap)
        .setFrameForPreview(frameForPreview)
        .setDecodedFrames(decodedFrames)
        .build();
    return new CloseableAnimatedImage(animatedImageResult);
  } finally {
    CloseableReference.closeSafely(previewBitmap);
    CloseableReference.closeSafely(decodedFrames);
  }
}
项目:GitHub    文件:AnimatedImageFactoryWebPImplTest.java   
@Test
public void testCreateDefaults() {
  WebPImage mockWebPImage = mock(WebPImage.class);

  // Expect a call to WebPImage.create
  TrivialPooledByteBuffer byteBuffer = createByteBuffer();
  when(mWebPImageMock.decode(byteBuffer.getNativePtr(), byteBuffer.size()))
      .thenReturn(mockWebPImage);

  EncodedImage encodedImage = new EncodedImage(
      CloseableReference.of(byteBuffer, FAKE_RESOURCE_RELEASER));
  encodedImage.setImageFormat(ImageFormat.UNKNOWN);

  CloseableAnimatedImage closeableImage =
      (CloseableAnimatedImage) mAnimatedImageFactory.decodeWebP(
          encodedImage,
          ImageDecodeOptions.defaults(),
          DEFAULT_BITMAP_CONFIG);

  // Verify we got the right result
  AnimatedImageResult imageResult = closeableImage.getImageResult();
  assertSame(mockWebPImage, imageResult.getImage());
  assertNull(imageResult.getPreviewBitmap());
  assertFalse(imageResult.hasDecodedFrame(0));

  // Should not have interacted with these.
  verifyZeroInteractions(mMockAnimatedDrawableBackendProvider);
  verifyZeroInteractions(mMockBitmapFactory);
}
项目:GitHub    文件:AnimatedImageFactoryGifImplTest.java   
@Test
public void testCreateDefaults() {
  GifImage mockGifImage = mock(GifImage.class);

  // Expect a call to GifImage.create
  TrivialPooledByteBuffer byteBuffer = createByteBuffer();
  when(mGifImageMock.decode(byteBuffer.getNativePtr(), byteBuffer.size()))
      .thenReturn(mockGifImage);

  EncodedImage encodedImage = new EncodedImage(
      CloseableReference.of(byteBuffer, FAKE_RESOURCE_RELEASER));
  encodedImage.setImageFormat(ImageFormat.UNKNOWN);

  CloseableAnimatedImage closeableImage =
      (CloseableAnimatedImage) mAnimatedImageFactory.decodeGif(
          encodedImage,
          ImageDecodeOptions.defaults(),
          DEFAULT_BITMAP_CONFIG);

  // Verify we got the right result
  AnimatedImageResult imageResult = closeableImage.getImageResult();
  assertSame(mockGifImage, imageResult.getImage());
  assertNull(imageResult.getPreviewBitmap());
  assertFalse(imageResult.hasDecodedFrame(0));

  // Should not have interacted with these.
  verifyZeroInteractions(mMockAnimatedDrawableBackendProvider);
  verifyZeroInteractions(mMockBitmapFactory);
}
项目:GitHub    文件:SvgDecoderExample.java   
@Override
public CloseableImage decode(
    EncodedImage encodedImage,
    int length,
    QualityInfo qualityInfo,
    ImageDecodeOptions options) {
  try {
    SVG svg = SVG.getFromInputStream(encodedImage.getInputStream());
    return new CloseableSvgImage(svg);
  } catch (SVGParseException e) {
    e.printStackTrace();
  }
  return null;
}
项目:GitHub    文件:ColorImageExample.java   
@Override
public CloseableImage decode(
    EncodedImage encodedImage,
    int length,
    QualityInfo qualityInfo,
    ImageDecodeOptions options) {
  try {
    // Read the file as a string
    String text = new String(ByteStreams.toByteArray(encodedImage.getInputStream()));

    // Check if the string matches "<color>#"
    if (!text.startsWith(COLOR_TAG + "#")) {
      return null;
    }

    // Parse the int value between # and <
    int startIndex = COLOR_TAG.length() + 1;
    int endIndex = text.lastIndexOf('<');
    int color = Integer.parseInt(text.substring(startIndex, endIndex), 16);

    // Add the alpha component so that we actually see the color
    color = ColorUtils.setAlphaComponent(color, 255);

    // Return the CloseableImage
    return new CloseableColorImage(color);
  } catch (IOException e) {
    e.printStackTrace();
  }
  // Return nothing if an error occurred
  return null;
}
项目:drawee-text-view    文件:DraweeSpan.java   
@VisibleForTesting
protected DataSource<CloseableReference<CloseableImage>> fetchDecodedImage() {
    ImagePipelineFactory factory;
    try {
        factory = ImagePipelineFactory.getInstance();
    } catch (NullPointerException e) {
        // Image pipeline is not initialized
        ImagePipelineFactory.initialize(mAttachedView.getContext().getApplicationContext());
        factory = ImagePipelineFactory.getInstance();
    }
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(getImageUri()))
            .setImageDecodeOptions(ImageDecodeOptions.newBuilder().setDecodePreviewFrame(true).build())
            .build();
    return factory.getImagePipeline().fetchDecodedImage(request, null);
}
项目:Li-MVPArms    文件:ConfigConstants.java   
public static ImageDecodeOptions getImageDecodeOptions(){
      ImageDecodeOptions decodeOptions = ImageDecodeOptions.newBuilder()
//            .setBackgroundColor(Color.TRANSPARENT)//图片的背景颜色
//            .setDecodeAllFrames(decodeAllFrames)//解码所有帧
//            .setDecodePreviewFrame(decodePreviewFrame)//解码预览框
//            .setForceOldAnimationCode(forceOldAnimationCode)//使用以前动画
//            .setFrom(options)//使用已经存在的图像解码
//            .setMinDecodeIntervalMs(intervalMs)//最小解码间隔(分位单位)
              .setUseLastFrameForPreview(true)//使用最后一帧进行预览
              .build();
      return decodeOptions;
  }
项目:H-Viewer    文件:ImageLoader.java   
public static void loadThumbFromUrl(Context context, ImageView imageView, int resizeWidthDp, int resizeHeightDp, String url, String cookie, String referer, ControllerListener controllerListener) {
    if (TextUtils.isEmpty(url)) {
        imageView.setImageURI(null);
        return;
    }
    Uri uri = Uri.parse(url);
    JsonObject header = new JsonObject();
    header.addProperty("Cookie", cookie);
    header.addProperty("Referer", referer);
    if (url != null && url.startsWith("http")) {
        if (HProxy.isEnabled() && HProxy.isAllowPicture()) {
            HProxy proxy = new HProxy(url);
            header.addProperty(proxy.getHeaderKey(), proxy.getHeaderValue());
            MyOkHttpNetworkFetcher.headers.put(uri, getGson().toJson(header));
        }
        MyOkHttpNetworkFetcher.headers.put(uri, getGson().toJson(header));
    }
    if (imageView instanceof SimpleDraweeView) {
        ImageDecodeOptions imageDecodeOptions = new ImageDecodeOptionsBuilder()
                .setForceStaticImage(true)
                .setDecodePreviewFrame(true)
                .build();
        ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri)
                .setResizeOptions(new ResizeOptions(DensityUtil.dp2px(context, resizeWidthDp), DensityUtil.dp2px(context, resizeHeightDp)))
                .setImageDecodeOptions(imageDecodeOptions)
                .setLocalThumbnailPreviewsEnabled(true)
                .build();
        DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setCallerContext(context)
                .setTapToRetryEnabled(true)
                .setAutoPlayAnimations(false)
                .setOldController(((SimpleDraweeView) imageView).getController())
                .setControllerListener(controllerListener)
                .setImageRequest(request)
                .build();
        ((SimpleDraweeView) imageView).setController(controller);
    }
}
项目:android-support-learn    文件:PApplication.java   
public static ImageDecodeOptions getImageDecodeOptions(){
        ImageDecodeOptions decodeOptions = ImageDecodeOptions.newBuilder()
//            .setBackgroundColor(Color.TRANSPARENT)//图片的背景颜色
//            .setDecodeAllFrames(decodeAllFrames)//解码所有帧
//            .setDecodePreviewFrame(decodePreviewFrame)//解码预览框
//            .setForceOldAnimationCode(forceOldAnimationCode)//使用以前动画
//            .setFrom(options)//使用已经存在的图像解码
//            .setMinDecodeIntervalMs(intervalMs)//最小解码间隔(分位单位)
                .setUseLastFrameForPreview(true)//使用最后一帧进行预览
                .build();
        return decodeOptions;
    }
项目:fresco    文件:AnimatedFactoryV2Impl.java   
@Override
public ImageDecoder getGifDecoder(final Bitmap.Config bitmapConfig) {
  return new ImageDecoder() {
    @Override
    public CloseableImage decode(
        EncodedImage encodedImage,
        int length,
        QualityInfo qualityInfo,
        ImageDecodeOptions options) {
      return getAnimatedImageFactory().decodeGif(encodedImage, options, bitmapConfig);
    }
  };
}
项目:fresco    文件:AnimatedFactoryV2Impl.java   
@Override
public ImageDecoder getWebPDecoder(final Bitmap.Config bitmapConfig) {
  return new ImageDecoder() {
    @Override
    public CloseableImage decode(
        EncodedImage encodedImage,
        int length,
        QualityInfo qualityInfo,
        ImageDecodeOptions options) {
      return getAnimatedImageFactory().decodeWebP(encodedImage, options, bitmapConfig);
    }
  };
}
项目:fresco    文件:AnimatedImageFactoryImpl.java   
private CloseableImage getCloseableImage(
    ImageDecodeOptions options,
    AnimatedImage image,
    Bitmap.Config bitmapConfig) {
  List<CloseableReference<Bitmap>> decodedFrames = null;
  CloseableReference<Bitmap> previewBitmap = null;
  try {
    final int frameForPreview = options.useLastFrameForPreview ? image.getFrameCount() - 1 : 0;
    if (options.forceStaticImage) {
      return new CloseableStaticBitmap(
          createPreviewBitmap(image, bitmapConfig, frameForPreview),
          ImmutableQualityInfo.FULL_QUALITY,
          0);
    }

    if (options.decodeAllFrames) {
      decodedFrames = decodeAllFrames(image, bitmapConfig);
      previewBitmap = CloseableReference.cloneOrNull(decodedFrames.get(frameForPreview));
    }

    if (options.decodePreviewFrame && previewBitmap == null) {
      previewBitmap = createPreviewBitmap(image, bitmapConfig, frameForPreview);
    }
    AnimatedImageResult animatedImageResult = AnimatedImageResult.newBuilder(image)
        .setPreviewBitmap(previewBitmap)
        .setFrameForPreview(frameForPreview)
        .setDecodedFrames(decodedFrames)
        .build();
    return new CloseableAnimatedImage(animatedImageResult);
  } finally {
    CloseableReference.closeSafely(previewBitmap);
    CloseableReference.closeSafely(decodedFrames);
  }
}
项目:fresco    文件:AnimatedImageFactoryWebPImplTest.java   
@Test
public void testCreateDefaults() {
  WebPImage mockWebPImage = mock(WebPImage.class);

  // Expect a call to WebPImage.create
  TrivialPooledByteBuffer byteBuffer = createByteBuffer();
  when(mWebPImageMock.decode(byteBuffer.getNativePtr(), byteBuffer.size()))
      .thenReturn(mockWebPImage);

  EncodedImage encodedImage = new EncodedImage(
      CloseableReference.of(byteBuffer, FAKE_RESOURCE_RELEASER));
  encodedImage.setImageFormat(ImageFormat.UNKNOWN);

  CloseableAnimatedImage closeableImage =
      (CloseableAnimatedImage) mAnimatedImageFactory.decodeWebP(
          encodedImage,
          ImageDecodeOptions.defaults(),
          DEFAULT_BITMAP_CONFIG);

  // Verify we got the right result
  AnimatedImageResult imageResult = closeableImage.getImageResult();
  assertSame(mockWebPImage, imageResult.getImage());
  assertNull(imageResult.getPreviewBitmap());
  assertFalse(imageResult.hasDecodedFrame(0));

  // Should not have interacted with these.
  verifyZeroInteractions(mMockAnimatedDrawableBackendProvider);
  verifyZeroInteractions(mMockBitmapFactory);
}
项目:fresco    文件:DefaultImageDecoder.java   
/**
 * Decodes gif into CloseableImage.
 *
 * @param encodedImage input image (encoded bytes plus meta data)
 * @return a CloseableImage
 */
public CloseableImage decodeGif(
    final EncodedImage encodedImage,
    final int length,
    final QualityInfo qualityInfo,
    final ImageDecodeOptions options) {
  if (!options.forceStaticImage && mAnimatedGifDecoder != null) {
    return mAnimatedGifDecoder.decode(encodedImage, length, qualityInfo, options);
  }
  return decodeStaticImage(encodedImage, options);
}
项目:fresco    文件:AnimatedImageFactoryGifImplTest.java   
@Test
public void testCreateDefaults() {
  GifImage mockGifImage = mock(GifImage.class);

  // Expect a call to GifImage.create
  TrivialPooledByteBuffer byteBuffer = createByteBuffer();
  when(mGifImageMock.decode(byteBuffer.getNativePtr(), byteBuffer.size()))
      .thenReturn(mockGifImage);

  EncodedImage encodedImage = new EncodedImage(
      CloseableReference.of(byteBuffer, FAKE_RESOURCE_RELEASER));
  encodedImage.setImageFormat(ImageFormat.UNKNOWN);

  CloseableAnimatedImage closeableImage =
      (CloseableAnimatedImage) mAnimatedImageFactory.decodeGif(
          encodedImage,
          ImageDecodeOptions.defaults(),
          DEFAULT_BITMAP_CONFIG);

  // Verify we got the right result
  AnimatedImageResult imageResult = closeableImage.getImageResult();
  assertSame(mockGifImage, imageResult.getImage());
  assertNull(imageResult.getPreviewBitmap());
  assertFalse(imageResult.hasDecodedFrame(0));

  // Should not have interacted with these.
  verifyZeroInteractions(mMockAnimatedDrawableBackendProvider);
  verifyZeroInteractions(mMockBitmapFactory);
}
项目:fresco    文件:SvgDecoderExample.java   
@Override
public CloseableImage decode(
    EncodedImage encodedImage,
    int length,
    QualityInfo qualityInfo,
    ImageDecodeOptions options) {
  try {
    SVG svg = SVG.getFromInputStream(encodedImage.getInputStream());
    return new CloseableSvgImage(svg);
  } catch (SVGParseException e) {
    e.printStackTrace();
  }
  return null;
}
项目:fresco    文件:ColorImageExample.java   
@Override
public CloseableImage decode(
    EncodedImage encodedImage,
    int length,
    QualityInfo qualityInfo,
    ImageDecodeOptions options) {
  try {
    // Read the file as a string
    String text = new String(ByteStreams.toByteArray(encodedImage.getInputStream()));

    // Check if the string matches "<color>#"
    if (!text.startsWith(COLOR_TAG + "#")) {
      return null;
    }

    // Parse the int value between # and <
    int startIndex = COLOR_TAG.length() + 1;
    int endIndex = text.lastIndexOf('<');
    int color = Integer.parseInt(text.substring(startIndex, endIndex), 16);

    // Add the alpha component so that we actually see the color
    color = ColorUtils.setAlphaComponent(color, 255);

    // Return the CloseableImage
    return new CloseableColorImage(color);
  } catch (IOException e) {
    e.printStackTrace();
  }
  // Return nothing if an error occurred
  return null;
}
项目:BlueBoard    文件:FrescoConfig.java   
public static ImageDecodeOptions getImageDecodeOptions() {
        ImageDecodeOptions decodeOptions = ImageDecodeOptions.newBuilder()
//            .setBackgroundColor(Color.TRANSPARENT)//图片的背景颜色
//            .setDecodeAllFrames(decodeAllFrames)//解码所有帧
//            .setDecodePreviewFrame(decodePreviewFrame)//解码预览框
//            .setForceOldAnimationCode(forceOldAnimationCode)//使用以前动画
//            .setFrom(options)//使用已经存在的图像解码
//            .setMinDecodeIntervalMs(intervalMs)//最小解码间隔(分位单位)
                .setUseLastFrameForPreview(true)//使用最后一帧进行预览
                .build();
        return decodeOptions;
    }
项目:GitHub    文件:ImageDecoder.java   
CloseableImage decode(
EncodedImage encodedImage,
int length,
QualityInfo qualityInfo,
ImageDecodeOptions options);