简体   繁体   中英

Fresco doesn't show image

I'm trying to show image in RecyclerView using Fresco. I have image in my file system and i want to display it in SimpleDraweeView by image location in String format. But in this view i have empty image. Log doesn't show any error. Can anyone help me? Here's my code where i'm trying to set the image:

    imageView.setVisibility(View.VISIBLE);
    if (new File(imageData.getLocation()).exists()){
        Uri fileLocationUri = Uri.parse("file:/" + imageData.getLocation());
        ImageRequest request = ImageRequest.fromUri(fileLocationUri);
        DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setImageRequest(request)
                .setOldController(imageView.getController())
                .setAutoPlayAnimations(true)
                .build();
        imageView.setController(controller);
    }

Image location is a string, which started with / , so Uri parser returns correct result. XML file:

<com.facebook.drawee.view.SimpleDraweeView
        a:id = "@+id/outgoing_photo_view"
        a:layout_width="300dp"
        a:layout_height="300dp"
        a:adjustViewBounds="true"
        a:visibility="gone"
        fresco:actualImageScaleType="focusCrop"
        fresco:placeholderImageScaleType="fitCenter"
        fresco:failureImageScaleType="centerInside"
        fresco:retryImageScaleType="centerCrop"
        fresco:roundAsCircle="false"
        fresco:roundedCornerRadius="1dp"
        fresco:roundTopLeft="true"
        fresco:roundTopRight="false"
        fresco:roundBottomLeft="false"
        fresco:roundBottomRight="true"
        fresco:roundingBorderWidth="2dp"/>

I guess your file URI is not valid.

It should work with something like this:

File file = ... // your file
Uri uri = Uri.fromFile(file); // to get a valid file:// URI
DraweeController controller = Fresco.newDraweeControllerBuilder()
        .setUri(uri)
        .build();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM