android 图片加载器,GitHub - yeinfo/Sketch: Sketch是Android上的一个功能强大且全面的图片加载器,能够帮助开发者从本地或网络读取图片,处理后显示在页面上。Sk...

ab05ad48fce34b27b6a08711e84018b3.png Sketch

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f416e64726f6964253230417273656e616c2d536b657463682d677265656e2e7376673f7374796c653d74727565

68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f7869616f70616e736b792f536b657463682e737667

Sketch是Android上的一个图片加载器,能够帮助开发者从本地或网络读取图片,处理后显示在页面上

5e3c0926729cf89a6d902aee1c68b4af.png

特点

支持gif图. 集成了android-gif-drawable 1.1.7可以方便的显示gif图片,感谢koral--

多种URI支持. 支持http://、https://、asset://、content://、file:///sdcard/sample.png、/sdcard/sample.jpg、drawable://等7种URI

二级缓存. 采用Lru算法在本地和内存中缓存图片,本地缓存默认最大容量为100M,内存缓存默认最大容量为最大可用内存的八分之一

各种列表支持. 在各种列表(ListView、RecyclerView)中循环使用不错位,并且不占用setTag()方法

SketchImageView. 使用SketchImageView只需调用display***Image()系列方法即可显示各种图片,并且支持显示下载进度,显示按下效果,点击重试等常用功能

重复下载过滤. 如果两个请求的图片地址一样的话,第二个就会等待第一个下载完成之后直接使用第一个下载的图片

即时取消无用请求. SketchImageView在onDetachedFromWindow()或被重复利用的时候会主动取消之前的请求

自动防止加载过大Bitmap 可通过maxSize来控制加载到内存的图片的尺寸,默认为屏幕宽高的0.75倍,还会自动根据ImageView的layout_width和layout_height来调整maxSize

独家TransitionDrawable支持. 独家支持任意尺寸的两张图片使用TransitionDrawable过渡显示,保证不变形

只加载或只下载. 除了display()方法可以显示图片之外,你还可以通过load()方法只加载图片到内存中或通过download()方法只下载图片到本地

支持读取APK图标. 支持直接读取本地APK文件的图标或根据包名和版本号读取已安装APP的图标

移动网络下暂停下载. 内置了移动网络下暂停下载图片的功能,你只需开启即可

自动选择合适的Bimtap.Config. 根据图片的MimeType自动选择合适的Bitmap.Config,减少内存浪费,例如对于JPEG格式的图片就会使用Bitmap.Config.RGB_565解码

特殊文件预处理. 提供ImagePreprocessor,可对本地的特殊文件(例如多媒体文件)进行预处理,Sketch便可直接显示其封面,读取APK文件的图标就是通过这个功能实现的

强大且灵活的自定义. 可自定义下载、缓存、解码、处理、显示、占位图等各个环节

示例APP

sketch-sample.png

示例

SketchImageView sketchImageView = findViewByID(R.id.image_main);

// display image from network

sketchImageView.displayImage("http://b.zol-img.com.cn/desk/bizhi/image/4/1366x768/1387347695254.jpg");

// display image from SDCard

sketchImageView.displayImage("/sdcard/sample.png");

sketchImageView.displayImage("file:///sdcard/sample.png");

// display apk icon from SDCard

sketchImageView.displayImage("/sdcard/google_play.apk");

// display installed app icon

sketchImageView.displayInstalledAppIcon("com.tencent.qq", 50001);

// display resource drawable

sketchImageView.displayResourceImage(R.drawable.sample);

// display image from asset

sketchImageView.displayAssetImage("sample.jpg");

// display image from URI

Uri uri = ...;

sketchImageView.displayURIImage(uri);

使用指南

从JCenter导入

dependencies{

compile 'me.xiaopan:sketch:lastVersionName'

}

lastVersionName:68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f7869616f70616e736b792f536b657463682e737667(不带v)

添加以下权限

最低支持Android2.2 API 7

支持的URI

Type

Scheme

Method

File in network

http://, https://

displayImage(String)

File in SDCard

/, file://

displayImage(String)

Content Provider

content://

displayURIImage(Uri)

Asset in app

asset://

displayAssetImage(String)

Resource in app

resource://

displayResourceImage(int)

支持的图片类型

|Type|Scheme|jpeg|png|webp|gif|apk icon|

|:---|:---|:---|:--|:---|:--|:---|:---|

|File in network|http://, http:// |YES|YES|YES(Android4.0 above)|YES|NO|

|File in SDCard|/, file:// |YES|YES|YES(Android4.0 above)|YES|YES|

|Content Provider|content:// |YES|YES|YES(Android4.0 above)|YES|NO|

|Asset in app|asset:// |YES|YES|YES(Android4.0 above)|YES|NO|

|Resource in app|resource:// |YES|YES|YES(Android4.0 above)|YES|NO|

download()、load()、display()

Sketch共有display()、load()、download()三个方法可供使用,你可以根据你的需求选择合适的方法

download()方法会下载图片到本地,并实现本地缓存

load()方法在download()方法的基础上,加载图片到内存中,并对图片进行处理

display()方法在load()方法的基础上,将图片缓存在内存中并显示在ImageView上

示例:

// 显示

Sketch.with(context).display("http://biying.png", sketchImageView)

.loadingImage(R.drawable.image_loading)

.commit();

// 加载

Sketch.with(context).load("http://biying.png", new LoadListener() {

@Override

public void onCompleted(Bitmap bitmap, ImageFrom imageFrom, String mimeType) {

}

@Override

public void onCompleted(GifDrawable gifDrawable, ImageFrom imageFrom, String mimeType) {

}

...

}).maxSize(100, 100).commit();

// 下载

Sketch.with(context).download("http://biying.png", new DownloadListener() {

@Override

public void onCompleted(File cacheFile, boolean isFromNetwork) {

}

...

}).commit();

load()和download()还支持同步执行,详情请参考同步执行load和download.md

下面是三种方法所支持的属性('-'代表不支持)

属性

download()

load()

display()

sync

false

false

-

requestLevel

NET

NET

NET

listener

null

null

null

downloadProgressListener

null

null

null

disableCacheInDisk

false

false

false

maxSize

-

屏幕的0.75倍

优先考虑ImageView的layout_width和layout_height

resize

-

null

null

forceUseResize

-

false

false

processor

-

null

null

decodeGifImage

-

false

false

lowQualityImage

-

false

false

bitmapConfig

-

null

null

inPreferQualityOverSpeed

-

false

false

disableCacheInMemory

-

-

false

displayer

-

-

DefaultImageDisplayer

loadingImage

-

-

null

failedImage

-

-

null

pauseDownloadImage

-

-

null

resizeByFixedSize

-

-

false

各属性的详细说明请参考配置各种属性.md

你可能还感兴趣的功能:

增强用户体验:

其它:

Thanks

License

Copyright (C) 2013 Peng fei Pan

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值