Translations: 简体中文
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.
- Support http, asset, content, android.resource and other URIs
- Support playing GIFs, WebP, HEIF and other animated image
- Support gesture zoom and large image sampling
- Supports download, conversion results, and memory L3 cache
- Support for correcting image orientation via Exif
- Supports Base64, video frames, SVG images
- Support for Jetpack Compose
- Supports automatic resizing of images according to the size of the view
- Supports loading only pictures to memory or downloading only pictures to disk
- Supports various useful features such as saving cellular data
- Support the extension of URI, cache, decoding, conversion, display, placeholder and other links
- Based on Kotlin and Kotlin coroutines
Published to mavenCentral
dependencies {
// The core functionality of Sketch is provided as well as a singleton and some
// handy extension functions that depend on this singleton implementation,
// and if you don't need a singleton, you can use the sketch-core module
implementation("io.github.panpf.sketch3:sketch:${LAST_VERSION}")
}
${LAST_VERSION}
: (Not included 'v')
There are also optional modules to extend the functionality of sketch:
dependencies {
// Support for Jetpack Compose.
// It relies on the singletons provided by the sketch module,
// and you can use the sketch-compose-core module if you don't need the singleton pattern
implementation("io.github.panpf.sketch3:sketch-compose:${LAST_VERSION}")
// Provides View with practical functions such as download progress,
// pausing loading during list sliding, saving cellular data,
// image type corner icons, loading apk files and installed app icons, etc.
// It relies on the singleton provided by the sketch module.
// If you do not need the singleton mode, you can use the sketch-view-core module.
implementation("io.github.panpf.sketch3:sketch-extensions-view:${LAST_VERSION}")
// Provide Compose with practical functions such as download progress,
// pausing loading during list sliding, saving cellular data,
// image type corner icons, loading apk files and installed app icons, etc.
implementation("io.github.panpf.sketch3:sketch-extensions-compose:${LAST_VERSION}")
// GIF playback is achieved through Android's built-in ImageDecoder and Movie class
implementation("io.github.panpf.sketch3:sketch-gif:${LAST_VERSION}")
// GifDrawable through Koral's android-gif-drawable library
implementation("io.github.panpf.sketch3:sketch-gif-koral:${LAST_VERSION}")
// Support for OkHttp
implementation("io.github.panpf.sketch3:sketch-okhttp:${LAST_VERSION}")
// SVG images are supported
implementation("io.github.panpf.sketch3:sketch-svg:${LAST_VERSION}")
// Video frames are read through Android's built-in MediaMetadataRetriever class
implementation("io.github.panpf.sketch3:sketch-video:${LAST_VERSION}")
// Video frames are read through wseemann's FFmpegMediaMetadataRetriever library
implementation("io.github.panpf.sketch3:sketch-video-ffmpeg:${LAST_VERSION}")
// Supports gesture zoom and jumbo sampling
implementation("io.github.panpf.sketch3:sketch-zoom:${LAST_VERSION}")
}
Sketch doesn't need to configure any obfuscation rules itself, but you may need to add obfuscation configurations for indirectly dependent Kotlin Coroutines, OkHttp, Okio.
Sketch provides a series of extended functions called displayImage for ImageView, which can easily display images
// 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...
You can also configure parameters through a trailing lambda function:
imageView.displayImage("https://www.sample.com/image.jpg") {
placeholder(R.drawable.placeholder)
error(R.drawable.error)
transformations(CircleCropTransformation())
crossfade()
// There is a lot more...
}
Important
Required import sketch-compose
module
AsyncImage(
imageUri = "https://www.sample.com/image.jpg",
modifier = Modifier.size(300.dp, 200.dp),
contentScale = ContentScale.Crop,
contentDescription = ""
)
// config params
AsyncImage(
rqeuest = DisplayRequest(LocalContext.current, "https://www.sample.com/image.jpg") {
placeholder(R.drawable.placeholder)
error(R.drawable.error)
transformations(BlurTransformation())
crossfade()
// There is a lot more...
},
modifier = Modifier.size(300.dp, 200.dp),
contentScale = ContentScale.Crop,
contentDescription = ""
)
Basic functions:
- Get Started
- AnimatedImage:GIF、WEBP、HEIF
- Resize:Modify the image size
- Transformation:Transformation image
- Transition:Display images in cool transitions
- StateImage:Placeholder and error images
- Listener:Listen for request status and download progress
- Cache:Learn about downloads, results, memory caching
- Fetcher:Learn about Fetcher and extend new URI types
- Decoder:Learn about Decoder and expand into new image types
- Target:Apply the load results to the target
- HttpStack:Learn about the HTTP section and using okhttp
- SVG:Decode SVG still images
- VideoFrames:Decode video frames
- Exif:Correct the image orientation
- ImageOptions:Manage image configurations in a unified manner
- RequestInterceptor:Intercept ImageRequest
- DecodeInterceptor:Intercept Bitmap or Drawable decoding
- BitmapPool:Reuse Bitmap to reduce GC
- DownloadRequest:Download the image to disk
- LoadRequest:Load the image to get the Bitmap
- Preload images into memory
- Lifecycle
- Jetpack Compose
- Log
Featured functions:
- SketchImageView:Configure the request through XML attributes
- SketchZoomImageView:Gesture zoom and large image sampling
- Improve the clarity of long images in grid lists
- Displays the download progress
- Displays the image type corner
- Pause image downloads on cellular data to save data
- The list slides to pause the loading of images
- Displays an icon for an apk file or installed app
Please review the CHANGELOG.md file
- The maven groupId was changed to 'io.github.panpf.sketch3', so version 2.* will not prompt for an upgrade
- The package name was changed to 'com.github.panpf.sketch' so it does not conflict with version 2.*
- Based on the kotlin coroutine rewrite, APIs and functions are all refactored as a new library
- There is no longer a requirement to use a SketchImageView, any ImageView and its subclasses will do, and any View can be supported in combination with a custom Target
- The Zoom function is split into independent modules that can be relied on separately, and the large image sampling function is refactored and supports multi-threaded decoding, which is faster
- The gif module now directly depends on the android-gif-drawable library, no longer modified twice, and can be upgraded by itself
- Support for Jetpack Compose
- Support for request and decode interceptors
- Referring to coil and combining with the original functionality of sketch, there are the
following differences compared to coil:
- sketch supports a minimum of API 16, while coil supports only API 21
- Sketch supports bitmap reuse, while coil does not
- Sketch supports more granular resizing of images
- sketch clearly distinguishes between display, load, and download requests
- sketch provides image scaling and display components and supports large image sampling
- coil-kt/coil: Sketch uses some code from Coil, including framework, compose, sketch-gif-movie parts
- bumptech/glide: BitmapPool
- chrisbanes/PhotoView: Zoom
- koral--/android-gif-drawable: gif-koral
- wseemann/FFmpegMediaMetadataRetriever: video-ffmpeg
- BigBadaboom/androidsvg: svg
The following are my other open source projects. If you are interested, you can learn about them:
- zoomimage:Library for zoom images, supported Android View, Compose and Compose Multiplatform; supported double-click zoom, One or two fingers gesture zoom, single-finger drag, inertial sliding, positioning, rotation, super-large image subsampling and other functions.
- assembly-adapter:A library on Android that provides multi-type Item implementations for various adapters. Incidentally, it also provides the most powerful divider for RecyclerView.
- sticky-item-decoration:RecyclerView sticky item implementation
Apache 2.0. See the LICENSE file for details.