Android Universal Image Loader

Universal-Image-Loader是一个非常好用的Android图片加载框架。

GitHub地址
ZIP包下载地址

Universal Image Loader

UIL(Universal Image Loader )的目的是提供一个功能强大,图像加载灵活和高度可定制的仪表,缓存和显示。它提供了大量的配置选项,并很好地控制图像加载和缓存过程。

这里写图片描述
项目新闻

  • 真的没有时间更新但无论如何UIL还活着:)

在新的扩展版即将到来的改变(UIL 1.9.4 +)

  • 支持内存缓存
  • 视频文件缩略图支持通过file:///sdcard/video.mp4
  • 新APIDisplayImageOptions.targetSize(ImageSize)
  • 支持HTTP缓存
  • 考虑添加BitmapFactory.Options.inBitmap
  • 文件在LruDiskCache生存时间的选择

    特征

  • 多线程加载图像(异步或同步)
  • 广泛的定制ImageLoader配置(线程的执行者,下载器、解码器、内存和磁盘缓存,显示图像选项等)
  • 许多自定义选项的每一个显示图像调用(存根图像,缓存开关,解码选项,位图处理和显示等)
  • 内存和/或磁盘上的图像缓存(设备的文件系统或SD卡)
  • 监听加载程序(包括下载进度)

Android 2.0+支持
下载
universal-image-loader-1.9.3.jar
universal-image-loader-1.9.3-with-sources.jar (for Eclipse)

文档

使用

合法的URI的例子

"http://site.com/image.png" // from Web
"file:///mnt/sdcard/image.png" // from SD card
"file:///mnt/sdcard/video.mp4" // from SD card (video thumbnail)
"content://media/external/images/media/13" // from content provider
"content://media/external/video/media/13" // from content provider (video thumbnail)
"assets://image.png" // from assets
"drawable://" + R.drawable.img // from drawables (non-9patch images)

注意:使用drawable://只有当你真的需要它!总是考虑负荷可-地道的ImageView.setImageResource(...)替代使用ImageLoader

简单的

// Load image, decode it to Bitmap and display Bitmap in ImageView (or any other view 
//  which implements ImageAware interface)
imageLoader.displayImage(imageUri, imageView);
// Load image, decode it to Bitmap and return Bitmap to callback
imageLoader.loadImage(imageUri, new SimpleImageLoadingListener() {
    @Override
    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
        // Do whatever you want with Bitmap
    }
});
// Load image, decode it to Bitmap and return Bitmap synchronously
Bitmap bmp = imageLoader.loadImageSync(imageUri);

完成

// Load image, decode it to Bitmap and display Bitmap in ImageView (or any other view 
//  which implements ImageAware interface)
imageLoader.displayImage(imageUri, imageView, options, new ImageLoadingListener() {
    @Override
    public void onLoadingStarted(String imageUri, View view) {
        ...
    }
    @Override
    public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
        ...
    }
    @Override
    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
        ...
    }
    @Override
    public void onLoadingCancelled(String imageUri, View view) {
        ...
    }
}, new ImageLoadingProgressListener() {
    @Override
    public void onProgressUpdate(String imageUri, View view, int current, int total) {
        ...
    }
});
// Load image, decode it to Bitmap and return Bitmap to callback
ImageSize targetSize = new ImageSize(80, 50); // result Bitmap will be fit to this size
imageLoader.loadImage(imageUri, targetSize, options, new SimpleImageLoadingListener() {
    @Override
    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
        // Do whatever you want with Bitmap
    }
});
// Load image, decode it to Bitmap and return Bitmap synchronously
ImageSize targetSize = new ImageSize(80, 50); // result Bitmap will be fit to this size
Bitmap bmp = imageLoader.loadImageSync(imageUri, targetSize, options);

加载和显示任务流程

这里写图片描述

捐助
你可以资助这个项目,并感谢作者的辛勤工作:)

替代方案

许可证

Copyright 2011-2015 Sergey Tarasevich

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,导入Module时,Gradle会报错,把提示那一行删掉即可。

此框架不足

不能加载gif图

不能指定图片特定角为圆角
通过自定义BitmapDisplayer来解决。
Android显示圆角图片,可指定图片某几个角为圆角
设置图片为圆角时不显示
需要给ImageView控件设置具体的宽高。
DisplayImageOptions.Builder().displayer(new RoundedBitmapDisplayer(20)),之后不显示图片的问题,是显示图片的控件在xml中必须设置大小才可以显示,也就是要先指定大小方可显示。

扩展
加载圆角图

DisplayImageOptions options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.apkol_award_user)
.showImageForEmptyUri(R.drawable.apkol_award_user)
.showImageOnFail(R.drawable.apkol_award_user)
.cacheInMemory(true).cacheOnDisc(true)
.bitmapConfig(Bitmap.Config.RGB_565) // 设置图片的解码类型
.displayer(new RoundedBitmapDisplayer(360))// 设置圆角弧度
.build();

    ImageLoader.getInstance().displayImage(currentPersion.USER_HEAD,
            personal_icon, options);

资源

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值