Skip to content
forked from panpf/sketch

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 等功能。

License

Notifications You must be signed in to change notification settings

Blackwen/sketch

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logo_image Sketch Image Loader

Platform API License version_icon QQ Group

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.

Features

  • 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

Import

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}: Download (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}")
}

R8 / Proguard

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.

Quickly Started

ImageView

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...
}

Jetpack Compose

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 = ""
)

Document

Basic functions:

Featured functions:

Changelog

Please review the CHANGELOG.md file

About version 3.0

  • 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

Special thanks

My Projects

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

License

Apache 2.0. See the LICENSE file for details.

About

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 等功能。

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 100.0%