use of com.facebook.imagepipeline.core.ImagePipeline in project BigImageViewer by Piasy.
the class FrescoImageLoader method loadImage.
@Override
public void loadImage(Uri uri, final Callback callback) {
ImageRequest request = ImageRequest.fromUri(uri);
File localCache = getCacheFile(request);
if (localCache.exists()) {
callback.onCacheHit(localCache);
} else {
// ensure `onStart` is called before `onProgress` and `onFinish`
callback.onStart();
// show 0 progress immediately
callback.onProgress(0);
ImagePipeline pipeline = Fresco.getImagePipeline();
DataSource<CloseableReference<PooledByteBuffer>> source = pipeline.fetchEncodedImage(request, true);
source.subscribe(new ImageDownloadSubscriber(mAppContext) {
@Override
protected void onProgress(int progress) {
callback.onProgress(progress);
}
@Override
protected void onSuccess(File image) {
callback.onFinish();
callback.onCacheMiss(image);
}
@Override
protected void onFail(Throwable t) {
// TODO: 12/11/2016 fail
t.printStackTrace();
}
}, mExecutorSupplier.forBackgroundTasks());
}
}
use of com.facebook.imagepipeline.core.ImagePipeline 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());
}
use of com.facebook.imagepipeline.core.ImagePipeline 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.core.ImagePipeline in project lzc_app_lib by httplzc.
the class BigImgDataRequestHelper method getDataBitmap.
// 获取图片的bitmap
private void getDataBitmap(final WrapperUri uri) {
ImagePipeline imagePipeline = Fresco.getImagePipeline();
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri.getUri()).setResizeOptions(new ResizeOptions(ScreenData.widthPX, ScreenData.heightPX)).build();
DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(request, "");
dataSource.subscribe(new BaseDataSubscriber<CloseableReference<CloseableImage>>() {
@Override
protected void onNewResultImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
if (!dataSource.isFinished()) {
return;
}
CloseableReference<CloseableImage> ref = dataSource.getResult();
if (ref != null && ref.isValid()) {
try {
data.put(uri.getUri(), ref.clone());
failSet.remove(uri.getUri());
if (imgDataLoadCompleteListener != null)
imgDataLoadCompleteListener.onRealDataLoadComplete(uri);
if (holderData.get(uri.getLowUri()) != null) {
CloseableReference refHolder = holderData.get(uri.getLowUri());
CloseableReference.closeSafely(refHolder);
holderData.remove(uri.getLowUri());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
CloseableReference.closeSafely(ref);
}
}
}
@Override
protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
if (holderData.get(uri.getLowUri()) != null) {
CloseableReference refHolder = holderData.get(uri.getLowUri());
CloseableReference.closeSafely(refHolder);
holderData.remove(uri.getLowUri());
}
if (imgDataLoadCompleteListener != null)
imgDataLoadCompleteListener.onRealDataFail(uri);
failSet.add(uri.getUri());
}
}, UiThreadImmediateExecutorService.getInstance());
}
use of com.facebook.imagepipeline.core.ImagePipeline in project lzc_app_lib by httplzc.
the class FunUntil method clearFrascoCache.
/**
* 清除图片缓存
*/
public static void clearFrascoCache() {
ImagePipeline imagePipeline = Fresco.getImagePipeline();
imagePipeline.clearCaches();
}
Aggregations