Sketch 是 Android 上的一个强大且全面的图片加载库,除了基础功能外,还支持 Jetpack Compose、GIF、SVG、视频缩略图、手势缩放、超大图采样、ExifInterface 等功能。Sketch is a powerful and comprehensive image load library on Android, in addition to the basic functions, it also supports Jetpack Compose, GIF, SVG, video thumbnails, gesture zoom, huge images sampling, ExifInterface and other functions.
Sketch 是 Android 上的一个强大且全面的图片加载库,除了基础功能外,还支持 Jetpack Compose、GIF、SVG、视频缩略图、手势缩放、超大图采样、ExifInterface 等功能。
Sketch is a powerful and comprehensive image load library on Android, in addition to the basic functions, it also supports Jetpack Compose, GIF, SVG, video thumbnails, gesture zoom, huge images sampling, ExifInterface and other functions.
io.github.panpf.sketch3
,因此 2.* 版本不会提示升级com.github.panpf.sketch
因此与 2.* 版本不会冲突已发布到 mavenCentral
dependencies {
implementation("io.github.panpf.sketch3:sketch:${LAST_VERSION}")
}
还有一些可选的模块用来扩展 sketch 的功能:
dependencies {
// 支持 Jetpack Compose
implementation("io.github.panpf.sketch3:sketch-compose:${LAST_VERSION}")
// 支持下载进度蒙层、列表滑动中暂停加载、节省蜂窝流量、图片类型角标、加载 apk 文件和已安装 app 图标等实用功能
implementation("io.github.panpf.sketch3:sketch-extensions:${LAST_VERSION}")
// 通过 koral 的 android-gif-drawable 库的 GifDrawable 实现 gif 播放
implementation("io.github.panpf.sketch3:sketch-gif-koral:${LAST_VERSION}")
// 通过 Android 内置的 Movie 类实现 gif 播放
implementation("io.github.panpf.sketch3:sketch-gif-movie:${LAST_VERSION}")
// 支持 OkHttp
implementation("io.github.panpf.sketch3:sketch-okhttp:${LAST_VERSION}")
// 支持 SVG 图片
implementation("io.github.panpf.sketch3:sketch-svg:${LAST_VERSION}")
// 通过 Android 内置的 MediaMetadataRetriever 类实现读取视频帧
implementation("io.github.panpf.sketch3:sketch-video:${LAST_VERSION}")
// 通过 wseemann 的 FFmpegMediaMetadataRetriever 库实现读取视频帧
implementation("io.github.panpf.sketch3:sketch-video-ffmpeg:${LAST_VERSION}")
// 支持手势缩放以及超大图采样
implementation("io.github.panpf.sketch3:sketch-zoom:${LAST_VERSION}")
}
sketch 自己不需要配置任何混淆规则,但你可能需要为间接依赖的 Kotlin Coroutines, OkHttp, Okio 添加混淆配置
Sketch 为 ImageView 提供了一系列的名为 displayImage 的扩展函数,可以方便的显示图片
// http
imageView.displayImage("https://www.sample.com/image.jpg")
// File
imageView.displayImage("/sdcard/download/image.jpg")
// asset
imageView.displayImage("asset://image.jpg")
// There is a lot more...
还可以通过尾随的 lambda 函数配置参数:
imageView.displayImage("https://www.sample.com/image.jpg") {
placeholder(R.drawable.placeholder)
error(R.drawable.error)
transformations(CircleCropTransformation())
crossfade()
// There is a lot more...
}
需要先导入 sketch-compose 模块
AsyncImage(
imageUri = "https://www.sample.com/image.jpg",
modifier = Modifier.size(300.dp, 200.dp),
contentScale = ContentScale.Crop,
contentDescription = ""
) {
placeholder(R.drawable.placeholder)
error(R.drawable.error)
transformations(CircleCropTransformation())
crossfade()
// There is a lot more...
}
基础功能:
特色功能:
请查看 CHANGELOG.md 文件
Copyright (C) 2022 panpf <[email protected]>
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
http://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.