Search in sources :

Example 46 with ResizeOptions

use of com.facebook.imagepipeline.common.ResizeOptions in project GalleryFinal by pengjianbo.

the class FrescoImageLoader method displayImage.

@Override
public void displayImage(Activity activity, String path, final GFImageView imageView, final Drawable defaultDrawable, int width, int height) {
    Resources resources = context.getResources();
    GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(resources).setFadeDuration(300).setPlaceholderImage(defaultDrawable).setFailureImage(defaultDrawable).setProgressBarImage(new ProgressBarDrawable()).build();
    final DraweeHolder<GenericDraweeHierarchy> draweeHolder = DraweeHolder.create(hierarchy, context);
    imageView.setOnImageViewListener(new GFImageView.OnImageViewListener() {

        @Override
        public void onDetach() {
            draweeHolder.onDetach();
        }

        @Override
        public void onAttach() {
            draweeHolder.onAttach();
        }

        @Override
        public boolean verifyDrawable(Drawable dr) {
            if (dr == draweeHolder.getHierarchy().getTopLevelDrawable()) {
                return true;
            }
            return false;
        }

        @Override
        public void onDraw(Canvas canvas) {
            Drawable drawable = draweeHolder.getHierarchy().getTopLevelDrawable();
            if (drawable == null) {
                imageView.setImageDrawable(defaultDrawable);
            } else {
                imageView.setImageDrawable(drawable);
            }
        }
    });
    Uri uri = new Uri.Builder().scheme(UriUtil.LOCAL_FILE_SCHEME).path(path).build();
    ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(uri).setResizeOptions(// 图片目标大小
    new ResizeOptions(width, height)).build();
    DraweeController controller = Fresco.newDraweeControllerBuilder().setOldController(draweeHolder.getController()).setImageRequest(imageRequest).build();
    draweeHolder.setController(controller);
}
Also used : ProgressBarDrawable(com.facebook.drawee.drawable.ProgressBarDrawable) GenericDraweeHierarchy(com.facebook.drawee.generic.GenericDraweeHierarchy) GenericDraweeHierarchyBuilder(com.facebook.drawee.generic.GenericDraweeHierarchyBuilder) DraweeController(com.facebook.drawee.interfaces.DraweeController) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) ProgressBarDrawable(com.facebook.drawee.drawable.ProgressBarDrawable) Uri(android.net.Uri) ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) Resources(android.content.res.Resources) GFImageView(cn.finalteam.galleryfinal.widget.GFImageView)

Example 47 with ResizeOptions

use of com.facebook.imagepipeline.common.ResizeOptions in project AgileDev by LZ9.

the class FrescoImageLoader method getImageRequest.

/**
 * 获取ImageRequest
 * @param bean 构建类
 */
private ImageRequest getImageRequest(FrescoBuilderBean bean) {
    ResizeOptions resizeOptions = null;
    if (bean.resizeWidth > 0 && bean.resizeHeight > 0) {
        // 配置内存中图片分辨率
        resizeOptions = new ResizeOptions(bean.resizeWidth, bean.resizeHeight);
    }
    BlurPostprocessor blurPostprocessor = null;
    if (bean.useBlur) {
        // 配置高斯模糊
        blurPostprocessor = new BlurPostprocessor(bean.blurRadius);
    }
    return ImageRequestBuilder.newBuilderWithSource((Uri) bean.path).setLocalThumbnailPreviewsEnabled(bean.localThumbnailPreviews).setResizeOptions(// 设置图片在内存的大小,类似分辨率
    resizeOptions).setRotationOptions(// 设置自动旋转
    RotationOptions.autoRotate()).setProgressiveRenderingEnabled(// 开启渐进式加载
    true).setPostprocessor(// 进行高斯模糊,配合setResizeOptions使用可以减少运算时间
    blurPostprocessor).build();
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions)

Example 48 with ResizeOptions

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

the class DownsampleUtilTest method whenRequestResizeWidthHeightAndMaxBitmapSize.

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());
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions)

Example 49 with ResizeOptions

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

the class DownsampleUtilTest method whenRequestResizeWidthHeightAndForcedRotation.

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));
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions)

Example 50 with ResizeOptions

use of com.facebook.imagepipeline.common.ResizeOptions 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)

Aggregations

ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)63 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)31 Uri (android.net.Uri)12 Test (org.junit.Test)11 DraweeController (com.facebook.drawee.interfaces.DraweeController)10 PipelineDraweeController (com.facebook.drawee.backends.pipeline.PipelineDraweeController)9 ImageRequestBuilder (com.facebook.imagepipeline.request.ImageRequestBuilder)7 GenericDraweeHierarchy (com.facebook.drawee.generic.GenericDraweeHierarchy)6 File (java.io.File)5 PipelineDraweeControllerBuilder (com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder)4 ColorDrawable (android.graphics.drawable.ColorDrawable)3 Drawable (android.graphics.drawable.Drawable)3 CloseableReference (com.facebook.common.references.CloseableReference)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