android 大图分块加载,GitHub - Bglgithub/sketch: Sketch是Android上一个强大且全面的图片加载器,支持GIF,手势缩放以及分块显示超大图片。Sketch i...

logo.png Sketch

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f416e64726f6964253230417273656e616c2d536b657463682d677265656e2e7376673f7374796c653d74727565

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d417061636865253230322d626c75652e737667

68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f7869616f70616e736b792f736b657463682e7376673f6c6162656c3d4c6f6773

68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f7869616f70616e736b792f736b657463682e7376673f6c6162656c3d4a43656e74657226636f6c6f72423d677265656e

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4150492d392532422d7265642e737667

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f51512545342542412541342545362542352538312545372542452541342d3532393633303734302d6f72616e67652e737667

Sketch是Android上一个强大且全面的图片加载器,支持GIF,手势缩放以及分块显示超大图片

sample.jpg

特点

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

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

独家手势缩放和超大图支持. 独家内置了手势缩放和分块显示超大图功能,并且结合的更好

三级缓存支持. 通过LruMemoryCache、LruDiskCache复用图片,加快显示时间;通过LruBitmapPool复用Bitmap,减少因GC而造成的卡顿

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

自动防止加载过大Bitmap 可通过maxSize来控制加载到内存的图片的尺寸,默认为ImageView的layout_width和layout_height或屏幕的宽高

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

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

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

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

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

特殊文件预处理. 通过ImagePreprocessor可对特殊文件(例如多媒体文件)进行预处理,提取出其包含的图片,读取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);

使用指南

导入

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

dependencies {

compile 'me.xiaopan:sketch:'

}

请自行替换 为最新的版本 68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f7869616f70616e736b792f736b657463682e7376673f6c6162656c3d4a43656e74657226636f6c6f72423d677265656e (不要"v")

如果需要播放GIF就添加sketch-gif的依赖

dependencies {

compile 'me.xiaopan:sketch-gif:'

}

请自行替换 为最新的版本 68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f7869616f70616e736b792f736b657463682e7376673f6c6162656c3d4a43656e74657226636f6c6f72423d677265656e (不要"v")

2.添加以下权限

3.Android 4.0以下需要在Application中调用释放缓存的方法(Android 4.0以上能直接通过Context注册并回调)

public class MyApplication extends Application {

@Override

public void onTrimMemory(int level) {

super.onTrimMemory(level);

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {

Sketch.with(getBaseContext()).onTrimMemory(level);

}

}

@Override

public void onLowMemory() {

super.onLowMemory();

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {

Sketch.with(getBaseContext()).onLowMemory();

}

}

}

最低支持Android2.3 API 9

支持的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://, https://

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(LoadResult loadResult) {

}

...

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

// 下载

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

@Override

public void onCompleted(DownloadResult downloadResult) {

}

...

}).commit();

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

你可能还感兴趣的功能:

基础功能:

进一步提升用户体验:

更多:

特别感谢

bumptech - glide (BitmapPool)

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值