use of com.facebook.imagepipeline.common.ResizeOptions in project boxing by Bilibili.
the class BoxingFrescoLoader method displayThumbnail.
@Override
public void displayThumbnail(@NonNull final ImageView img, @NonNull final String absPath, int width, int height) {
String finalAbsPath = "file://" + absPath;
ImageRequestBuilder requestBuilder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(finalAbsPath));
requestBuilder.setResizeOptions(new ResizeOptions(width, height));
ImageRequest request = requestBuilder.build();
final DataSource<CloseableReference<CloseableImage>> dataSource = Fresco.getImagePipeline().fetchDecodedImage(request, null);
dataSource.subscribe(new BaseDataSubscriber<CloseableReference<CloseableImage>>() {
@Override
protected void onNewResultImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
String path = (String) img.getTag(R.string.boxing_app_name);
if (path == null || absPath.equals(path)) {
if (dataSource.getResult() == null) {
onFailureImpl(dataSource);
return;
}
Drawable drawable = createDrawableFromFetchedResult(img.getContext(), dataSource.getResult().get());
img.setImageDrawable(drawable);
}
}
@Override
protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
img.setImageResource(R.drawable.ic_boxing_broken_image);
}
}, UiThreadImmediateExecutorService.getInstance());
}
use of com.facebook.imagepipeline.common.ResizeOptions in project boxing by Bilibili.
the class BoxingFrescoLoader method displayRaw.
@Override
public void displayRaw(@NonNull ImageView img, @NonNull String absPath, int width, int height, IBoxingCallback callback) {
absPath = "file://" + absPath;
ImageRequestBuilder requestBuilder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(absPath));
if (width > 0 && height > 0) {
requestBuilder.setResizeOptions(new ResizeOptions(width, height));
}
ImageRequest request = requestBuilder.build();
loadImage(request, img, callback);
}
use of com.facebook.imagepipeline.common.ResizeOptions in project SherlockAdapter by EvilBT.
the class FrescoUtil method resizeImage.
public static void resizeImage(@NonNull final SimpleDraweeView view, @NonNull final String path, final int viewWidth) {
Preconditions.checkNotNull(view);
Preconditions.checkNotNull(path);
ControllerListener<ImageInfo> controllerListener = new BaseControllerListener<ImageInfo>() {
@Override
public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
if (imageInfo == null) {
return;
}
final float width = imageInfo.getWidth();
final float height = imageInfo.getHeight();
if (width * height != 0.0f) {
final int viewHeight = (int) (height * viewWidth / width);
setResizeImage(view, path, new ResizeOptions(viewWidth, viewHeight));
}
}
};
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(path)).build();
view.setController(Fresco.newDraweeControllerBuilder().setImageRequest(request).setOldController(view.getController()).setControllerListener(controllerListener).build());
}
use of com.facebook.imagepipeline.common.ResizeOptions in project SherlockAdapter by EvilBT.
the class FrescoUtil method setWrapAndResizeImage.
public static void setWrapAndResizeImage(@NonNull final SimpleDraweeView view, @NonNull final String path, final int viewWidth, @Nullable final Point size) {
Preconditions.checkNotNull(view);
Preconditions.checkNotNull(path);
ControllerListener<ImageInfo> controllerListener = new BaseControllerListener<ImageInfo>() {
@Override
public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
if (imageInfo == null) {
return;
}
final float width = imageInfo.getWidth();
final float height = imageInfo.getHeight();
if (width * height != 0.0f) {
view.setAspectRatio(width / height);
final int viewHeight = (int) (height * viewWidth / width);
if (size != null) {
size.set(viewWidth, viewHeight);
}
setResizeImage(view, path, new ResizeOptions(viewWidth, viewHeight));
}
}
};
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(path)).build();
view.setController(Fresco.newDraweeControllerBuilder().setImageRequest(request).setOldController(view.getController()).setControllerListener(controllerListener).build());
}
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);
}
Aggregations