Coil

Kotlin 协程支持的 Android 图像加载。「Image loading for Android backed by Kotlin Coroutines.」

Github星跟踪图

原文:https://github.com/coil-kt/coil/blob/master/README-zh.md


Coil

Coil 是一个 Android 图片加载库,通过 Kotlin 协程的方式加载图片。特点:

  • 更快: Coil 在性能上有很多优化包括内存缓存和磁盘缓存,把缩略图存保存在内存中,循环利用 bitmap,自动暂停和取消图片网络请求等。
  • 更轻量级: Coil 只有 2000 个方法(前提是你的 APP 里面集成了 OkHttp 和 Coroutines),Coil 和 Picasso 的方法数差不多相比 Glide 和 Fresco 要轻量级很多。
  • 更容易使用: Coil's API 充分利用了 Kotlin 语言的新特性简化和减少了很多重复的代码。
  • 更流行: Coil 首选 Kotlin 语言开发并且使用包含 Coroutines, OkHttp, Okio 和 AndroidX Lifecycles 在内的最流行的开源库。

Coil 的首字母由来:取 Coroutine,Image 和 Loader 得来 Coil。

Instacartheart打造。

下载

Coil 允许使用mavenCentral().

implementation("io.coil-kt:coil:1.0.0")
    

快速使用

可以使用ImageView的扩展函数load 加载一张图片:

// URL
imageView.load("https://www.example.com/image.jpg")
// Resource
imageView.load(R.drawable.image)
// File
imageView.load(File("/path/to/image.jpg"))
// And more...
        

可以使用lambda语法轻松配置请求选项:

imageView.load("https://www.example.com/image.jpg") {
    crossfade(true)
    placeholder(R.drawable.image)
    transformations(CircleCropTransformation())
}
        

也可以查看 Coli 文档获得更多信息: 完整的文档在这里

环境要求

R8 / Proguard

Coil 兼容 R8 混淆您无需再添加其他的规则

如果您需要混淆代码,你可能需要添加对应的混淆规则:Coroutines, OkHttpOkio

许可证

Copyright 2020 Coil Contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
   https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
        

概览

名称与所有者coil-kt/coil
主编程语言Kotlin
编程语言Kotlin (语言数: 3)
平台Android
许可证Apache License 2.0
发布数55
最新版本名称3.0.0-alpha06 (发布于 )
第一版名称0.6.0 (发布于 )
创建于2019-08-10 21:28:21
推送于2024-05-18 17:54:53
最后一次提交
星数10.3k
关注者数104
派生数635
提交数1.6k
已启用问题?
问题数784
打开的问题数42
拉请求数1106
打开的拉请求数4
关闭的拉请求数135
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?

Coil

An image loading library for Android backed by Kotlin Coroutines. Coil is:

  • Fast: Coil performs a number of optimizations including memory and disk caching, downsampling the image in memory, re-using Bitmaps, automatically pausing/cancelling requests, and more.
  • Lightweight: Coil adds ~1500 methods to your APK (for apps that already use OkHttp and Coroutines), which is comparable to Picasso and significantly less than Glide and Fresco.
  • Easy to use: Coil's API leverages Kotlin's language features for simplicity and minimal boilerplate.
  • Modern: Coil is Kotlin-first and uses modern libraries including Coroutines, OkHttp, Okio, and AndroidX Lifecycles.

Coil is an acronym for: Coroutine Image Loader.

Made with ❤️ at Instacart. Translations: 한국어

Download

Coil is available on mavenCentral().

implementation("io.coil-kt:coil:0.6.1")

Quick Start

To load an image into an ImageView, use the load extension function:

// URL
imageView.load("https://www.example.com/image.jpg")

// Resource
imageView.load(R.drawable.image)

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

// And more...

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())
}

To get an image imperatively, use the get suspend function:

val drawable = Coil.get("https://www.example.com/image.jpg")

Coil requires Java 8 bytecode. Here's how to enable it.

Check out Coil's full documentation here.

Requirements

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

R8 / Proguard

Coil is fully compatible with R8 out of the box and doesn't require adding any extra rules.

If you use Proguard, you may need to add rules for Coroutines, OkHttp and Okio.

License

Copyright 2019 Coil Contributors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
去到顶部