Search in sources :

Example 1 with RotationOptions

use of com.facebook.imagepipeline.common.RotationOptions 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 2 with RotationOptions

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

the class SimpleImageTranscoder method transcode.

@Override
public ImageTranscodeResult transcode(EncodedImage encodedImage, OutputStream outputStream, @Nullable RotationOptions rotationOptions, @Nullable ResizeOptions resizeOptions, @Nullable ImageFormat outputFormat, @Nullable Integer quality) {
    if (quality == null) {
        quality = JpegTranscoderUtils.DEFAULT_JPEG_QUALITY;
    }
    if (rotationOptions == null) {
        rotationOptions = RotationOptions.autoRotate();
    }
    final int sampleSize = this.getSampleSize(encodedImage, rotationOptions, resizeOptions);
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = sampleSize;
    Bitmap resizedBitmap;
    try {
        resizedBitmap = BitmapFactory.decodeStream(encodedImage.getInputStream(), null, options);
    } catch (OutOfMemoryError oom) {
        FLog.e(TAG, "Out-Of-Memory during transcode", oom);
        return new ImageTranscodeResult(TranscodeStatus.TRANSCODING_ERROR);
    }
    if (resizedBitmap == null) {
        FLog.e(TAG, "Couldn't decode the EncodedImage InputStream ! ");
        return new ImageTranscodeResult(TranscodeStatus.TRANSCODING_ERROR);
    }
    Matrix transformationMatrix = JpegTranscoderUtils.getTransformationMatrix(encodedImage, rotationOptions);
    Bitmap srcBitmap = resizedBitmap;
    try {
        if (transformationMatrix != null) {
            srcBitmap = Bitmap.createBitmap(resizedBitmap, 0, 0, resizedBitmap.getWidth(), resizedBitmap.getHeight(), transformationMatrix, false);
        }
        srcBitmap.compress(getOutputFormat(outputFormat), quality, outputStream);
        return new ImageTranscodeResult(sampleSize > DownsampleUtil.DEFAULT_SAMPLE_SIZE ? TranscodeStatus.TRANSCODING_SUCCESS : TranscodeStatus.TRANSCODING_NO_RESIZING);
    } catch (OutOfMemoryError oom) {
        FLog.e(TAG, "Out-Of-Memory during transcode", oom);
        return new ImageTranscodeResult(TranscodeStatus.TRANSCODING_ERROR);
    } finally {
        srcBitmap.recycle();
        resizedBitmap.recycle();
    }
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) RotationOptions(com.facebook.imagepipeline.common.RotationOptions) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) BitmapFactory(android.graphics.BitmapFactory)

Example 3 with RotationOptions

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

the class ImagePipelineUtilsImplTest method testBuildImageRequest_whenRotatingEnabled_thenSetRotateOptions.

@Test
public void testBuildImageRequest_whenRotatingEnabled_thenSetRotateOptions() {
    RotationOptions rotationOptions = RotationOptions.forceRotation(RotationOptions.ROTATE_270);
    final ImageOptions imageOptions = ImageOptions.create().rotate(rotationOptions).build();
    ImageRequest imageRequest = mImagePipelineUtils.buildImageRequest(URI, imageOptions);
    assertThat(imageRequest).isNotNull();
    assertThat(imageRequest.getSourceUri()).isEqualTo(URI);
    assertThat(imageRequest.getRotationOptions()).isEqualTo(rotationOptions);
}
Also used : ImageRequest(com.facebook.imagepipeline.request.ImageRequest) ImageOptions(com.facebook.fresco.vito.options.ImageOptions) RotationOptions(com.facebook.imagepipeline.common.RotationOptions) Test(org.junit.Test)

Aggregations

RotationOptions (com.facebook.imagepipeline.common.RotationOptions)3 ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)2 Bitmap (android.graphics.Bitmap)1 BitmapFactory (android.graphics.BitmapFactory)1 Matrix (android.graphics.Matrix)1 ImageOptions (com.facebook.fresco.vito.options.ImageOptions)1 ImageDecodeOptions (com.facebook.imagepipeline.common.ImageDecodeOptions)1 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)1 Postprocessor (com.facebook.imagepipeline.request.Postprocessor)1 Nullable (javax.annotation.Nullable)1 Test (org.junit.Test)1