AIImageLoader

Loads images from the web at the size they show at, and keeps the latest ones in memory, so what scrolls back into view shows its images at once.

The agent writes every link, so an image downloads only from a public host: every address the host resolves to must be public, so not the device itself or the local network, and each redirect, up to ImageDownloader.MaxRedirects, is checked the same way.

Each image downloads up to a number of bytes, and decodes upright, as its EXIF orientation says, to no more than MaxDecodedPixels. Callers that ask for an image while it loads wait for the same load, which stops once none of them waits any more, such as when the UI that asked for it leaves the screen.

Properties

Link copied to clipboard

The most pixels an image decodes to: 2048 x 2048, 16 MB at 4 bytes a pixel.

Link copied to clipboard

The most bytes an image downloads by default.

Functions

Link copied to clipboard
fun cached(url: String, targetSizePx: Int): Bitmap?

The image at url at targetSizePx, when it is in memory.

Link copied to clipboard

Whether url is one this loader downloads: a web link. The agent writes every link, so nothing on the device is read for it.

Link copied to clipboard
suspend fun load(url: String, targetSizePx: Int, maxBytes: Int = MaxDownloadBytes): Bitmap?

The image at url, sampled down to about targetSizePx, or null when it can't be loaded, such as when it is larger than maxBytes.