androidfresco

How to display a local Bitmap to SimpleDraweeView


I have a SimpleDraweeView and can display an image correctly by:

SimpleDraweeView draweeView = (SimpleDraweeView) findViewById(R.id.hotel_image_view);
            draweeView.setImageURI(uri);

but sometimes i want to use a local image like @drawable not from a URL, but setImageBitmap or setImageResource can't be used:

draweeView.setImageBitmap(R.drawable.test_image);

How could i do this? Use an ImageView under SimperDrweeView hide/show by some condition to use local image? Thanks.


Solution

  • You can put a @drawable in a Fresco image request. This is one way:

    ImageRequest request =
        ImageRequestBuilder.newBuilderWithResourceId(R.drawable.test_image)
                           .build();
    DraweeController controller = Fresco.newDraweeControllerBuilder()
        .setImageRequest(request)
        .setOldController(draweeView.getController())
        .build();
    draweeView.setController(controller);