1 Star 0 Fork 0

pandalhhhh / sketch

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 9.87 KB
一键复制 编辑 原始数据 按行查看 历史
panpfpanpf 提交于 2021-05-25 17:00 . Migrated to mavenCentral

logo_image Sketch Image Loader

Platform Android Arsenal License API version_icon QQ Group

English version of the README.md

Sketch 是 Android 上一款强大且全面的图片加载器,除了图片加载的必备功能外,还支持 GIF,手势缩放、分块显示超大图片、自动纠正图片方向、显示视频缩略图等功能

示例 APP

sample_app_download_qrcode

扫描二维码下载或点我下载

特性

支持的特性

  • 多种 URI 支持. 支持 http://https://asset://content://file:///sdcard/sample.jpg/sdcard/sample.jpgdrawable://data:image/data:img/android.resource://apk.icon://app.icon:// 等 URI,通过 UriModel 还可以扩展支持的 URI
  • 支持 gif 图片. 集成了 android-gif-drawable 1.2.19 可以方便的显示 gif 图片
  • 支持手势缩放. 支持手势缩放功能,在 PhotoView 的基础上进行了优化,增加了滚动条,定位等功能
  • 支持分块显示超大图. 支持分块显示超大图功能,从此再大的图片也不怕了
  • 支持三级缓存. 通过 LruMemoryCache、LruDiskCache 复用图片,加快显示时间;通过 LruBitmapPool 复用 Bitmap,减少因 GC 而造成的卡顿
  • 支持纠正图片方向. 可纠正方向不正的图片,并且分块显示超大图功能也支持,仅限 JPEG 格式的图片
  • 支持显示 APK 或 APP 图标. 支持显示本地 APK 文件的图标或根据包名和版本号显示已安装APP的图标
  • 支持 Base64 图片. 支持解析 Base64 格式的图片
  • 支持各种列表. 在各种列表(ListView、RecyclerView)中循环使用不错位,并且不占用 setTag() 方法
  • 自动防止加载过大 Bitmap 可通过 maxSize 来控制加载到内存的图片的尺寸,默认为 ImageView的 layout_width 和 layout_height 或屏幕的宽高
  • 独家 TransitionDrawable 支持. 独家支持任意尺寸的两张图片使用 TransitionDrawable 过渡显示,保证不变形
  • 只加载或只下载. 除了 display() 方法可以显示图片之外,你还可以通过 load() 方法只加载图片到内存中或通过 download() 方法只下载图片到本地
  • 移动数据下暂停下载. 内置了移动数据下暂停下载图片的功能,你只需开启即可
  • 自动选择合适的 Bitmap.Config. 根据图片的 MimeType 自动选择合适的 Bitmap.Config,减少内存浪费,例如对于 JPEG 格式的图片就会使用 Bitmap.Config.RGB_565 解码
  • 强大且灵活的自定义. 可自定义 URI 支持、HTTP、下载、缓存、解码、处理、显示、占位图等各个环节

支持的 URI

Type Scheme
File in network http://, https://
File in SDCard /, file://
Content Resolver content://
Asset Resource asset://
Drawable Resource drawable://
Base64 data:image/, data:/img/
APK Icon apk.icon://
APP Icon app.icon://
Android Resource android.resource://

详情请参考 URI 类型及使用指南

支持的图片类型

  • jpeg
  • png
  • gif
  • bmp
  • webp

开始使用

从 mavenCentral 导入 Sketch

在 app 的 build.gradle 文件的 dependencies 节点中加入依赖

implementation("io.github.panpf.sketch:sketch:${LAST_VERSION}")
implementation("io.github.panpf.sketch:sketch-gif:${LAST_VERSION}") // 不是必须的. 如果需要支持 gif 就添加

${LAST_VERSION}: Download (不包含 'v')

使用 SketchImageView 显示图片

SketchImageView sketchImageView = (SketchImageView) findViewById(R.id.image_main);
sketchImageView.displayImage("http://t.cn/RShdS1f");

文档

基础功能:

提升用户体验:

更多:

更新日志

Please view the CHANGELOG.md file

特别感谢

交流群

  • QQ Group

License

Copyright (C) 2019 Peng fei Pan <panpfpanpf@outlook.me>

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.
1
https://gitee.com/pandalhhhh/sketch.git
git@gitee.com:pandalhhhh/sketch.git
pandalhhhh
sketch
sketch
master

搜索帮助