use of com.facebook.imagepipeline.request.ImageRequest in project ride-read-android by Ride-Read.
the class MapFragment method addMoment2Map.
private void addMoment2Map(final MapMoment moment) {
final LatLng latLng = new LatLng(moment.getLatitude(), moment.getLongitude());
ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(moment.getPictures().get(0) + QiNiuUtils.CROP_SMALL_100)).setProgressiveRenderingEnabled(true).build();
ImagePipeline imagePipeline = Fresco.getImagePipeline();
DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, Utils.getAppContext());
dataSource.subscribe(new BaseBitmapDataSubscriber() {
@Override
public void onNewResultImpl(@Nullable Bitmap bitmap) {
addMomentMarker(latLng, bitmap, moment);
}
@Override
public void onFailureImpl(DataSource dataSource) {
}
}, CallerThreadExecutor.getInstance());
}
use of com.facebook.imagepipeline.request.ImageRequest 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.request.ImageRequest 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.request.ImageRequest 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.request.ImageRequest in project SherlockAdapter by EvilBT.
the class FrescoUtil method save.
public static Boolean save(@NonNull String url, @NonNull File outputFile) throws IOException {
ImagePipelineFactory factory = Fresco.getImagePipelineFactory();
ImagePipeline pipeline = factory.getImagePipeline();
boolean isInCache = pipeline.isInDiskCacheSync(Uri.parse(url));
if (isInCache) {
BinaryResource resource = factory.getMainFileCache().getResource(new SimpleCacheKey(url));
if (resource instanceof FileBinaryResource) {
FileBinaryResource fileResource = (FileBinaryResource) resource;
FileChannel input = new FileInputStream(fileResource.getFile()).getChannel();
FileChannel output = new FileOutputStream(outputFile).getChannel();
output.transferFrom(input, 0, input.size());
input.close();
output.close();
return true;
}
}
boolean isMemoryCache = pipeline.isInBitmapMemoryCache(Uri.parse(url));
if (!isMemoryCache) {
return false;
}
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url)).build();
DataSource<CloseableReference<CloseableImage>> dataSource = pipeline.fetchImageFromBitmapCache(request, null);
if (!dataSource.isFinished()) {
return false;
}
CloseableReference<CloseableImage> closeableImageRef = dataSource.getResult();
Bitmap bitmap = null;
if (closeableImageRef != null && closeableImageRef.get() instanceof CloseableBitmap) {
bitmap = ((CloseableBitmap) closeableImageRef.get()).getUnderlyingBitmap();
}
if (bitmap == null) {
return false;
}
FileOutputStream outputStream = new FileOutputStream(outputFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
outputStream.flush();
outputStream.close();
return true;
}
Aggregations