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);
}
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();
}
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());
}
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));
}
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();
}
}
Aggregations