Search in sources :

Example 11 with ResizeOptions

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

the class ImagePipelineUtilsImpl method createDecodedImageRequestBuilder.

@Nullable
protected ImageRequestBuilder createDecodedImageRequestBuilder(@Nullable ImageRequestBuilder imageRequestBuilder, DecodedImageOptions imageOptions) {
    if (imageRequestBuilder == null) {
        return null;
    }
    ResizeOptions resizeOptions = imageOptions.getResizeOptions();
    if (resizeOptions != null) {
        imageRequestBuilder.setResizeOptions(resizeOptions);
    }
    RotationOptions rotationOptions = imageOptions.getRotationOptions();
    if (rotationOptions != null) {
        imageRequestBuilder.setRotationOptions(rotationOptions);
    }
    ImageDecodeOptions imageDecodeOptions = mImageDecodeOptionsProvider.create(imageRequestBuilder, imageOptions);
    if (imageDecodeOptions != null) {
        imageRequestBuilder.setImageDecodeOptions(imageDecodeOptions);
    }
    imageRequestBuilder.setLocalThumbnailPreviewsEnabled(imageOptions.areLocalThumbnailPreviewsEnabled());
    Postprocessor postprocessor = imageOptions.getPostprocessor();
    if (postprocessor != null) {
        imageRequestBuilder.setPostprocessor(postprocessor);
    }
    if (imageOptions.isProgressiveDecodingEnabled() != null) {
        imageRequestBuilder.setProgressiveRenderingEnabled(imageOptions.isProgressiveDecodingEnabled());
    }
    return imageRequestBuilder;
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) Postprocessor(com.facebook.imagepipeline.request.Postprocessor) RotationOptions(com.facebook.imagepipeline.common.RotationOptions) ImageDecodeOptions(com.facebook.imagepipeline.common.ImageDecodeOptions) Nullable(javax.annotation.Nullable)

Example 12 with ResizeOptions

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

the class DraweeRecyclerViewFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    final RecyclerView recyclerView = view.findViewById(R.id.recycler_view);
    recyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {

        @Override
        public void onLayoutChange(View view, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
            final int imageSize = (right - left) / SPAN_COUNT;
            mResizeOptions = new ResizeOptions(imageSize, imageSize);
        }
    });
    GridLayoutManager layoutManager = new GridLayoutManager(getContext(), SPAN_COUNT);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setHasFixedSize(true);
    final SimpleAdapter adapter = new SimpleAdapter(new ArrayList<Uri>());
    recyclerView.setAdapter(adapter);
    final Spinner imageSource = view.findViewById(R.id.spinner_image_source);
    ImageSourceSpinner.INSTANCE.setup(imageSource, sampleUris(), new Function1<List<Uri>, Unit>() {

        @Override
        public Unit invoke(List<Uri> uris) {
            adapter.setData(uris);
            return null;
        }
    });
}
Also used : ImageSourceSpinner(com.facebook.fresco.samples.showcase.misc.ImageSourceSpinner) Spinner(android.widget.Spinner) Unit(kotlin.Unit) SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Uri(android.net.Uri) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) RecyclerView(androidx.recyclerview.widget.RecyclerView) ArrayList(java.util.ArrayList) List(java.util.List)

Example 13 with ResizeOptions

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

the class FrescoHolder method onBind.

@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);
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) DraweeController(com.facebook.drawee.interfaces.DraweeController) Uri(android.net.Uri) ImageRequestBuilder(com.facebook.imagepipeline.request.ImageRequestBuilder)

Example 14 with ResizeOptions

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

the class ImagePipelineUtilsImplTest method testBuildImageRequest_whenResizingEnabled_thenSetResizeOptions.

@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);
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) ImageOptions(com.facebook.fresco.vito.options.ImageOptions) Test(org.junit.Test)

Example 15 with ResizeOptions

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

the class ResizeAndRotateProducerTest method testResizeRatio.

@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);
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) PrepareOnlyThisForTest(org.powermock.core.classloader.annotations.PrepareOnlyThisForTest) Test(org.junit.Test)

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