use of com.facebook.imagepipeline.request.ImageRequest in project DevRing by LJYcoder.
the class FrescoManager method preLoad.
@Override
public void preLoad(String url) {
ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(Preconditions.checkNotNull(url, "预加载的图片路径不能为空"))).build();
Fresco.getImagePipeline().prefetchToBitmapCache(imageRequest, null);
Fresco.getImagePipeline().prefetchToDiskCache(imageRequest, null);
}
use of com.facebook.imagepipeline.request.ImageRequest in project DevRing by LJYcoder.
the class FrescoManager method getBitmap.
@Override
public void getBitmap(Context context, String url, final ImageListener<Bitmap> imageListener) {
// 参考自https://github.com/hpdx/fresco-helper/blob/master/fresco-helper/src/main/java/com/facebook/fresco/helper/ImageLoader.java
Uri uri = Uri.parse(url);
ImagePipeline imagePipeline = Fresco.getImagePipeline();
ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(uri);
ImageRequest imageRequest = builder.build();
DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);
dataSource.subscribe(new BaseDataSubscriber<CloseableReference<CloseableImage>>() {
@Override
public void onNewResultImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
if (!dataSource.isFinished()) {
return;
}
CloseableReference<CloseableImage> imageReference = dataSource.getResult();
if (imageReference != null) {
final CloseableReference<CloseableImage> closeableReference = imageReference.clone();
try {
CloseableImage closeableImage = closeableReference.get();
// 动图处理
if (closeableImage instanceof CloseableAnimatedImage) {
AnimatedImageResult animatedImageResult = ((CloseableAnimatedImage) closeableImage).getImageResult();
if (animatedImageResult != null && animatedImageResult.getImage() != null) {
int imageWidth = animatedImageResult.getImage().getWidth();
int imageHeight = animatedImageResult.getImage().getHeight();
Bitmap.Config bitmapConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = Bitmap.createBitmap(imageWidth, imageHeight, bitmapConfig);
animatedImageResult.getImage().getFrame(0).renderFrame(imageWidth, imageHeight, bitmap);
if (imageListener != null) {
imageListener.onSuccess(bitmap);
}
}
} else // 非动图处理
if (closeableImage instanceof CloseableBitmap) {
CloseableBitmap closeableBitmap = (CloseableBitmap) closeableImage;
Bitmap bitmap = closeableBitmap.getUnderlyingBitmap();
if (bitmap != null && !bitmap.isRecycled()) {
// https://github.com/facebook/fresco/issues/648
final Bitmap tempBitmap = bitmap.copy(bitmap.getConfig(), false);
if (imageListener != null) {
imageListener.onSuccess(tempBitmap);
}
}
}
} finally {
imageReference.close();
closeableReference.close();
}
}
}
@Override
public void onFailureImpl(DataSource dataSource) {
Throwable throwable = dataSource.getFailureCause();
if (imageListener != null) {
imageListener.onFail(throwable);
}
}
}, UiThreadImmediateExecutorService.getInstance());
}
use of com.facebook.imagepipeline.request.ImageRequest in project DevRing by LJYcoder.
the class FrescoManager method load.
private void load(Uri uri, ImageView imageView, LoadOption loadOption) {
Preconditions.checkNotNull(imageView, "加载图片的控件不能为空!");
if (imageView instanceof SimpleDraweeView) {
SimpleDraweeView simpleDraweeView = (SimpleDraweeView) imageView;
setHierarchay(simpleDraweeView.getHierarchy(), loadOption);
ImageRequest imageRequest = getImageRequest(uri, simpleDraweeView, loadOption);
DraweeController draweeController = getController(imageRequest, simpleDraweeView.getController());
simpleDraweeView.setController(draweeController);
} else {
throw new IllegalArgumentException("Fresco加载图片的控件需为SimpleDraweeView");
}
}
use of com.facebook.imagepipeline.request.ImageRequest in project MyDiary by erttyy8821.
the class DiaryPhotoLayout method setPhotoUri.
public void setPhotoUri(Uri photoUri) {
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(photoUri).setResizeOptions(new ResizeOptions(DiaryItemHelper.getVisibleWidth(getContext()), DiaryItemHelper.getVisibleHeight(getContext()))).setRotationOptions(RotationOptions.autoRotate()).build();
DraweeController controller = Fresco.newDraweeControllerBuilder().setImageRequest(request).build();
SDV_diary_new_photo.setController(controller);
}
use of com.facebook.imagepipeline.request.ImageRequest in project fresco by facebook.
the class PipelineDraweeControllerBuilder method getCacheKey.
private CacheKey getCacheKey() {
final ImageRequest imageRequest = getImageRequest();
final CacheKeyFactory cacheKeyFactory = mImagePipeline.getCacheKeyFactory();
CacheKey cacheKey = null;
if (cacheKeyFactory != null && imageRequest != null) {
if (imageRequest.getPostprocessor() != null) {
cacheKey = cacheKeyFactory.getPostprocessedBitmapCacheKey(imageRequest, getCallerContext());
} else {
cacheKey = cacheKeyFactory.getBitmapCacheKey(imageRequest, getCallerContext());
}
}
return cacheKey;
}
Aggregations