Search in sources :

Example 6 with ResizeOptions

use of com.facebook.imagepipeline.common.ResizeOptions in project fresco by facebook.

the class DownsampleUtil method determineSampleSize.

/**
   * Get the factor between the dimensions of the encodedImage (actual image) and the ones of the
   * imageRequest (requested size).
   *
   * @param imageRequest the request containing the requested dimensions
   * @param encodedImage the encoded image with the actual dimensions
   * @return
   */
public static int determineSampleSize(ImageRequest imageRequest, EncodedImage encodedImage) {
    if (!EncodedImage.isMetaDataAvailable(encodedImage)) {
        return DEFAULT_SAMPLE_SIZE;
    }
    float ratio = determineDownsampleRatio(imageRequest, encodedImage);
    int sampleSize;
    if (encodedImage.getImageFormat() == DefaultImageFormats.JPEG) {
        sampleSize = ratioToSampleSizeJPEG(ratio);
    } else {
        sampleSize = ratioToSampleSize(ratio);
    }
    // Check the case when the dimension of the downsampled image is still larger than the max
    // possible dimension for an image.
    int maxDimension = Math.max(encodedImage.getHeight(), encodedImage.getWidth());
    final ResizeOptions resizeOptions = imageRequest.getResizeOptions();
    final float maxBitmapSize = resizeOptions != null ? resizeOptions.maxBitmapSize : BitmapUtil.MAX_BITMAP_SIZE;
    while (maxDimension / sampleSize > maxBitmapSize) {
        if (encodedImage.getImageFormat() == DefaultImageFormats.JPEG) {
            sampleSize *= 2;
        } else {
            sampleSize++;
        }
    }
    return sampleSize;
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions)

Example 7 with ResizeOptions

use of com.facebook.imagepipeline.common.ResizeOptions in project fresco by facebook.

the class DownsampleUtil method determineDownsampleRatio.

@VisibleForTesting
static float determineDownsampleRatio(ImageRequest imageRequest, EncodedImage encodedImage) {
    Preconditions.checkArgument(EncodedImage.isMetaDataAvailable(encodedImage));
    final ResizeOptions resizeOptions = imageRequest.getResizeOptions();
    if (resizeOptions == null || resizeOptions.height <= 0 || resizeOptions.width <= 0 || encodedImage.getWidth() == 0 || encodedImage.getHeight() == 0) {
        return 1.0f;
    }
    final int rotationAngle = getRotationAngle(imageRequest, 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 for %s", resizeOptions.width, resizeOptions.height, widthAfterRotation, heightAfterRotation, widthRatio, heightRatio, ratio, imageRequest.getSourceUri().toString());
    return ratio;
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) VisibleForTesting(com.facebook.common.internal.VisibleForTesting)

Example 8 with ResizeOptions

use of com.facebook.imagepipeline.common.ResizeOptions in project DevRing by LJYcoder.

the class FrescoManager method getImageRequest.

/**
 * 构建、获取ImageRequest
 *
 * @param uri              加载路径
 * @param simpleDraweeView 加载的图片控件
 * @param loadOption       临时加载选项
 * @return ImageRequest
 */
private ImageRequest getImageRequest(Uri uri, SimpleDraweeView simpleDraweeView, LoadOption loadOption) {
    int width;
    int height;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        width = simpleDraweeView.getWidth();
        height = simpleDraweeView.getHeight();
    } else {
        width = simpleDraweeView.getMaxWidth();
        height = simpleDraweeView.getMaxHeight();
    }
    // 根据加载路径生成ImageRequest的构造者
    ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(uri);
    // 调整解码图片的大小
    if (width > 0 && height > 0) {
        builder.setResizeOptions(new ResizeOptions(width, height));
    }
    // 是否开启渐进式加载,仅支持JPEG图片
    builder.setProgressiveRenderingEnabled(true);
    if (loadOption != null) {
        // 图片变换处理
        CombinePostProcessors.Builder processorBuilder = new CombinePostProcessors.Builder();
        if (loadOption.getBlurRadius() > 0) {
            processorBuilder.add(new BlurPostprocessor(mContext, loadOption.getBlurRadius()));
        }
        if (loadOption.isGray()) {
            processorBuilder.add(new GrayscalePostprocessor());
        }
        builder.setPostprocessor(processorBuilder.build());
    }
    return builder.build();
}
Also used : BlurPostprocessor(jp.wasabeef.fresco.processors.BlurPostprocessor) GrayscalePostprocessor(jp.wasabeef.fresco.processors.GrayscalePostprocessor) ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) PipelineDraweeControllerBuilder(com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder) ImageRequestBuilder(com.facebook.imagepipeline.request.ImageRequestBuilder) CombinePostProcessors(jp.wasabeef.fresco.processors.CombinePostProcessors) ImageRequestBuilder(com.facebook.imagepipeline.request.ImageRequestBuilder)

Example 9 with ResizeOptions

use of com.facebook.imagepipeline.common.ResizeOptions in project lzc_app_lib by httplzc.

the class BigImgDataRequestHelper method getDataBitmap.

// 获取图片的bitmap
private void getDataBitmap(final WrapperUri uri) {
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri.getUri()).setResizeOptions(new ResizeOptions(ScreenData.widthPX, ScreenData.heightPX)).build();
    DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(request, "");
    dataSource.subscribe(new BaseDataSubscriber<CloseableReference<CloseableImage>>() {

        @Override
        protected void onNewResultImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
            if (!dataSource.isFinished()) {
                return;
            }
            CloseableReference<CloseableImage> ref = dataSource.getResult();
            if (ref != null && ref.isValid()) {
                try {
                    data.put(uri.getUri(), ref.clone());
                    failSet.remove(uri.getUri());
                    if (imgDataLoadCompleteListener != null)
                        imgDataLoadCompleteListener.onRealDataLoadComplete(uri);
                    if (holderData.get(uri.getLowUri()) != null) {
                        CloseableReference refHolder = holderData.get(uri.getLowUri());
                        CloseableReference.closeSafely(refHolder);
                        holderData.remove(uri.getLowUri());
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    CloseableReference.closeSafely(ref);
                }
            }
        }

        @Override
        protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
            if (holderData.get(uri.getLowUri()) != null) {
                CloseableReference refHolder = holderData.get(uri.getLowUri());
                CloseableReference.closeSafely(refHolder);
                holderData.remove(uri.getLowUri());
            }
            if (imgDataLoadCompleteListener != null)
                imgDataLoadCompleteListener.onRealDataFail(uri);
            failSet.add(uri.getUri());
        }
    }, UiThreadImmediateExecutorService.getInstance());
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) CloseableReference(com.facebook.common.references.CloseableReference) ImagePipeline(com.facebook.imagepipeline.core.ImagePipeline)

Example 10 with ResizeOptions

use of com.facebook.imagepipeline.common.ResizeOptions in project lzc_app_lib by httplzc.

the class FunUntil method loadImg.

/**
 * 加载图片
 * @param targetWidth
 * @param targetHeight
 * @param simpleDraweeView
 * @param uri
 * @param rotate
 */
public static void loadImg(int targetWidth, int targetHeight, SimpleDraweeView simpleDraweeView, Uri uri, int rotate) {
    if (uri == null)
        return;
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri).setRotationOptions(RotationOptions.forceRotation(rotate)).setResizeOptions(new ResizeOptions(targetWidth, targetHeight)).setLowestPermittedRequestLevel(ImageRequest.RequestLevel.FULL_FETCH).build();
    AbstractDraweeController controller = Fresco.newDraweeControllerBuilder().setOldController(simpleDraweeView.getController()).setImageRequest(request).build();
    simpleDraweeView.setController(controller);
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) AbstractDraweeController(com.facebook.drawee.controller.AbstractDraweeController)

Aggregations

ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)59 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)27 Uri (android.net.Uri)12 Test (org.junit.Test)11 DraweeController (com.facebook.drawee.interfaces.DraweeController)10 ImageRequestBuilder (com.facebook.imagepipeline.request.ImageRequestBuilder)7 PipelineDraweeController (com.facebook.drawee.backends.pipeline.PipelineDraweeController)5 File (java.io.File)5 PipelineDraweeControllerBuilder (com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder)4 Drawable (android.graphics.drawable.Drawable)3 CloseableReference (com.facebook.common.references.CloseableReference)3 GenericDraweeHierarchy (com.facebook.drawee.generic.GenericDraweeHierarchy)3 EncodedImage (com.facebook.imagepipeline.image.EncodedImage)3 FileSystemReference (im.actor.runtime.files.FileSystemReference)3 Context (android.content.Context)2 Canvas (android.graphics.Canvas)2 Point (android.graphics.Point)2 Animatable (android.graphics.drawable.Animatable)2 View (android.view.View)2 Spinner (android.widget.Spinner)2