Search in sources :

Example 91 with ImageRequest

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());
}
Also used : Bitmap(android.graphics.Bitmap) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) CloseableReference(com.facebook.common.references.CloseableReference) LatLng(com.amap.api.maps.model.LatLng) ImagePipeline(com.facebook.imagepipeline.core.ImagePipeline) BaseBitmapDataSubscriber(com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber) DataSource(com.facebook.datasource.DataSource)

Example 92 with ImageRequest

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());
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) CloseableReference(com.facebook.common.references.CloseableReference) Drawable(android.graphics.drawable.Drawable) AnimatedDrawable(com.facebook.imagepipeline.animated.base.AnimatedDrawable) OrientedDrawable(com.facebook.drawee.drawable.OrientedDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ImageRequestBuilder(com.facebook.imagepipeline.request.ImageRequestBuilder)

Example 93 with ImageRequest

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);
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) ImageRequestBuilder(com.facebook.imagepipeline.request.ImageRequestBuilder)

Example 94 with ImageRequest

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);
}
Also used : ProgressBarDrawable(com.facebook.drawee.drawable.ProgressBarDrawable) GenericDraweeHierarchy(com.facebook.drawee.generic.GenericDraweeHierarchy) GenericDraweeHierarchyBuilder(com.facebook.drawee.generic.GenericDraweeHierarchyBuilder) DraweeController(com.facebook.drawee.interfaces.DraweeController) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) ProgressBarDrawable(com.facebook.drawee.drawable.ProgressBarDrawable) Uri(android.net.Uri) ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) Resources(android.content.res.Resources) GFImageView(cn.finalteam.galleryfinal.widget.GFImageView)

Example 95 with ImageRequest

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;
}
Also used : ImagePipelineFactory(com.facebook.imagepipeline.core.ImagePipelineFactory) FileChannel(java.nio.channels.FileChannel) CloseableReference(com.facebook.common.references.CloseableReference) CloseableImage(com.facebook.imagepipeline.image.CloseableImage) FileBinaryResource(com.facebook.binaryresource.FileBinaryResource) FileInputStream(java.io.FileInputStream) CloseableBitmap(com.facebook.imagepipeline.image.CloseableBitmap) CloseableBitmap(com.facebook.imagepipeline.image.CloseableBitmap) Bitmap(android.graphics.Bitmap) BinaryResource(com.facebook.binaryresource.BinaryResource) FileBinaryResource(com.facebook.binaryresource.FileBinaryResource) FileOutputStream(java.io.FileOutputStream) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) ImagePipeline(com.facebook.imagepipeline.core.ImagePipeline)

Aggregations

ImageRequest (com.facebook.imagepipeline.request.ImageRequest)100 ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)26 DraweeController (com.facebook.drawee.interfaces.DraweeController)25 CloseableReference (com.facebook.common.references.CloseableReference)24 Uri (android.net.Uri)18 ImagePipeline (com.facebook.imagepipeline.core.ImagePipeline)17 Test (org.junit.Test)14 Bitmap (android.graphics.Bitmap)13 CacheKey (com.facebook.cache.common.CacheKey)12 File (java.io.File)11 DataSource (com.facebook.datasource.DataSource)10 BaseBitmapDataSubscriber (com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber)9 CloseableImage (com.facebook.imagepipeline.image.CloseableImage)8 ImageRequestBuilder (com.facebook.imagepipeline.request.ImageRequestBuilder)8 Animatable (android.graphics.drawable.Animatable)7 PipelineDraweeController (com.facebook.drawee.backends.pipeline.PipelineDraweeController)7 BaseControllerListener (com.facebook.drawee.controller.BaseControllerListener)7 ImageOptions (com.facebook.fresco.vito.options.ImageOptions)7 ImageInfo (com.facebook.imagepipeline.image.ImageInfo)7 EncodedImage (com.facebook.imagepipeline.image.EncodedImage)6