use of com.facebook.imagepipeline.request.ImageRequest in project teaTime by ancfdy.
the class FrescoUtils method localImg.
/**
* 缩略图预览(仅支持本地图片,并且是JPEG图片格式)
* @param draweeView
* @param uri
*/
public static void localImg(SimpleDraweeView draweeView, Uri uri) {
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri).setLocalThumbnailPreviewsEnabled(true).build();
DraweeController controller = Fresco.newDraweeControllerBuilder().setImageRequest(request).setOldController(draweeView.getController()).build();
draweeView.setController(controller);
}
use of com.facebook.imagepipeline.request.ImageRequest in project teaTime by ancfdy.
the class FrescoUtils method loadImage.
/**
* 请求图片
* @param uri - 唯一的必选的成员. 参考 支持的URIs
* @param width
* @param height
* autoRotateEnabled - 是否支持自动旋转.
* progressiveEnabled - 是否支持渐进式加载.
* postprocessor - 后处理器(postprocess).
* resizeOptions - 图片缩放选项,用前请先阅读缩放和旋转
*/
public static void loadImage(SimpleDraweeView draweeView, String uri, int width, int height) {
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(uri)).setAutoRotateEnabled(// 是否支持自动旋转.
true).setImageDecodeOptions(// 图片解码库
getImageDecodeOptions()).setLowestPermittedRequestLevel(//请求经过缓存级别 BITMAP_MEMORY_CACHE,ENCODED_MEMORY_CACHE,DISK_CACHE,FULL_FETCH
RequestLevel.FULL_FETCH).setProgressiveRenderingEnabled(//渐进加载,主要用于渐进式的JPEG图,影响图片显示速度(普通)
false).setResizeOptions(new ResizeOptions(width, height)).build();
DraweeController controller = Fresco.newDraweeControllerBuilder().setImageRequest(request).setOldController(draweeView.getController()).build();
draweeView.setController(controller);
}
use of com.facebook.imagepipeline.request.ImageRequest in project SherlockAdapter by EvilBT.
the class FrescoUtil method setWrapImage.
public static void setWrapImage(@NonNull final SimpleDraweeView view, @NonNull final String path) {
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);
}
}
};
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.request.ImageRequest in project SherlockAdapter by EvilBT.
the class FrescoUtil method setResizeImage.
public static void setResizeImage(@NonNull final SimpleDraweeView view, @NonNull final String path, @NonNull ResizeOptions resize) {
Preconditions.checkNotNull(view);
Preconditions.checkNotNull(path);
Preconditions.checkNotNull(resize);
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(path)).setResizeOptions(resize).build();
view.setController(Fresco.newDraweeControllerBuilder().setImageRequest(request).setOldController(view.getController()).setAutoPlayAnimations(true).build());
}
use of com.facebook.imagepipeline.request.ImageRequest in project DevRing by LJYcoder.
the class FrescoManager method downLoadImage.
@Override
public void downLoadImage(Context context, String url, final File saveFile, final ImageListener<File> 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<PooledByteBuffer>> dataSource = imagePipeline.fetchEncodedImage(imageRequest, context);
dataSource.subscribe(new BaseDataSubscriber<CloseableReference<PooledByteBuffer>>() {
@Override
public void onNewResultImpl(DataSource<CloseableReference<PooledByteBuffer>> dataSource) {
if (!dataSource.isFinished()) {
return;
}
CloseableReference<PooledByteBuffer> imageReference = dataSource.getResult();
if (imageReference != null) {
final CloseableReference<PooledByteBuffer> closeableReference = imageReference.clone();
try {
PooledByteBuffer pooledByteBuffer = closeableReference.get();
InputStream inputStream = new PooledByteBufferInputStream(pooledByteBuffer);
OutputStream outputStream = new FileOutputStream(saveFile);
if (FileUtil.saveFile(inputStream, outputStream) && imageListener != null) {
imageListener.onSuccess(saveFile);
}
} catch (Exception e) {
if (imageListener != null) {
imageListener.onFail(e);
}
e.printStackTrace();
} finally {
imageReference.close();
closeableReference.close();
}
}
}
@Override
public void onProgressUpdate(DataSource<CloseableReference<PooledByteBuffer>> dataSource) {
int progress = (int) (dataSource.getProgress() * 100);
RingLog.d("fresco下载图片进度:" + progress);
}
@Override
public void onFailureImpl(DataSource dataSource) {
Throwable throwable = dataSource.getFailureCause();
if (imageListener != null) {
imageListener.onFail(throwable);
}
}
}, Executors.newSingleThreadExecutor());
}
Aggregations