• Stars
    star
    1,934
  • Rank 23,032 (Top 0.5 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created over 10 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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.

More Repositories

1

spider-web-score-view

SpiderWebScoreView 是 Android 上的一个蛛网评分控件 SpiderWebScoreView Android is used on a cobweb score view
Java
640
star
2

switch-button

SwitchButton 是 Android 上的一个开关按钮控件 【Deprecated】【Stop maintenance】
Java
332
star
3

assembly-adapter

AssemblyAdapter 是 Android 上的一个为各种 Adapter 提供开箱即用实现的库。AssemblyAdapter is a library on Android that provides out-of-the-box implementations for various Adapters.
Kotlin
173
star
4

pager-indicator

这是 Android 上的一个 ViewPager 页面指示器组件,用于标识当前显示的页面
Java
139
star
5

bintray-publish

Super easy way to publish your Android and Java artifacts to bintray.
Groovy
97
star
6

scratch-award-view

这是一个刮刮卡组件,用于实现刮奖效果
Java
52
star
7

stickyitemdecoration

RecyclerView 黏性 item 实现。RecyclerView sticky item implementation.
Kotlin
18
star
8

android-sheller

Sheller 是 Android 上的一个 shell 库,可帮助开发者方便的执行 shell 命令
Java
11
star
9

view-expander

ViewExpander 用来快速实现 View 展开关闭效果,使用非常简单,适用于所有的 View
Java
10
star
10

barcode-utils

BarcodeUtils 是一个条码解析、生成、扫描库,基于 zxing 封装,适合快速在项目中集成条码相关功能
Java
7
star
11

android-activitymonitor

Android, Activity, Monitor
Java
4
star
12

zoomimage

Android library for scaling images, supporting double-tap zoom, gesture zoom, single-finger drag, inertial swipe, location, rotate, huge image sub-sampling loading, and more. Both View and Compose are supported. 用于缩放图像的 Android 库,支持双击缩放、手势缩放、单指拖动、惯性滑动、定位、旋转、超大图采样加载等功能。支持 View 和 Compose。
Kotlin
3
star
13

tools4a

Extensions to the Android standard library and support libraries and some basic tools
Java
2
star
14

maven-publish-gradle-plugin

Gradle plugin that configures an uploadArchives task to automatically upload all of your Java, Kotlin or Android libraries to any Maven instance.
Kotlin
2
star
15

tools4k

Extensions to the Kotlin standard library
Kotlin
2
star
16

tools4j

Extensions to the Java standard library, some tool methods related to File, IO, primitive types, String, Array, and Collection
Java
2
star
17

android-liveevent

Java
1
star
18

jsonx

Extensions to the org.json standard library
Java
1
star