Image Requests
If you need an ImageRequest that consists only of a URI, you can use the helper method ImageRequest.fromURI. Loading multiple-images is a common case of this.
If you need to tell the image pipeline anything more than a simple URI, you need to use ImageRequestBuilder:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Uri uri;
ImageDecodeOptions decodeOptions = ImageDecodeOptions.newBuilder()
    .setBackgroundColor(Color.GREEN)
    .build();
ImageRequest request = ImageRequestBuilder
    .newBuilderWithSource(uri)
    .setImageDecodeOptions(decodeOptions)
    .setAutoRotateEnabled(true)
    .setLocalThumbnailPreviewsEnabled(true)
    .setLowestPermittedRequestLevel(RequestLevel.FULL_FETCH)
    .setProgressiveRenderingEnabled(false)
    .setResizeOptions(new ResizeOptions(width, height))
    .build();
Fields in ImageRequest
- uri- the only mandatory field. See Supported URIs
- autoRotateEnabled- whether to enable auto-rotation.
- progressiveEnabled- whether to enable progressive loading.
- postprocessor- component to postprocess the decoded image.
- resizeOptions- desired width and height. Use with caution. See Resizing.
Lowest Permitted Request Level
The image pipeline follows a definite sequence in where it looks for the image.
- Check the bitmap cache. This is nearly instant. If found, return.
- Check the encoded memory cache. If found, decode the image and return.
- Check the “disk” (local storage) cache. If found, load from disk, decode, and return.
- Go to the original file on network or local file. Download, resize and/or rotate if requested, decode, and return. For network images in particular, this will be the slowest by a long shot.
The setLowestPermittedRequestLevel field lets you control how far down this list the pipeline will go. Possible values are:
- BITMAP_MEMORY_CACHE
- ENCODED_MEMORY_CACHE
- DISK_CACHE
- FULL_FETCH
This is useful in situations where you need an instant, or at least relatively fast, image or none at all.
