画像読み込みライブラリ「COIL」

Glide や Picasso のような画像読み込みライブラリです。

COroutine
Image
Loader

の略だそうです。

以下の特徴を持っており、ナウい感じです。

- 拡張関数、ラムダなどKotlinの持つ機能を活用。
- コルーチンを利用。
- ディスクキャッシュとストリームバッファリング機能。
- androidx.lifecycle に対応。
- 軽量。
- R8対応。ルール不要。

👉 Introducing Coil: Kotlin-first image loading on Android 

記述例です。


// To load an image into an ImageView, use the load extension function.
imageView.load("https://www.example.com/image.jpg")

// Coil supports urls, uris, resources, drawables, bitmaps, files, and more.
imageView.load(R.drawable.image)

imageView.load(File("/path/to/image.jpg"))

imageView.load(Uri.parse("content://com.android.externalstorage/image.jpg"))

// Requests can be configured with an optional trailing lambda.
imageView.load("https://www.example.com/image.jpg") {
    crossfade(true)
    placeholder(R.drawable.image)
    transformations(CircleCropTransformation())
}

// Custom targets can be created using lambda syntax (onStart and onError are optional).
Coil.load(context, "https://www.example.com/image.jpg") {
    target { drawable ->
        // Handle the successful result.
    }
}

// To get an image imperatively, use the get suspend function.
val drawable = Coil.get("https://www.example.com/image.jpg")

👉 GitHub - coil-kt/coil: Image loading for Android backed by Kotlin Coroutines. 

パフォーマンスを Glide や Picasso と比較した記事がありますが、まあまあのようです。

Coil is a new library, so its performance may increase in the next versions. We are comparing it with mature libraries, so let’s see how it evolves.

Coil は新しいライブラリであるため、次のバージョンでパフォーマンスが向上する可能性があります。成熟したライブラリと比較しているので、どのように進化するか見ておきましょう。

👉 Coil vs Picasso vs Glide: Get Ready… Go! - ProAndroidDev 

ちなみに、必要環境は以下。

- AndroidX
- Min SDK 14+
- Compile SDK: 28+
- Java 8+

今後に期待できますかね。