1.Picasso简单介绍

Picasso是Square公司出品的一个强大的图片下载和缓存图片库。官方网址是:http://square.github.io/picasso/

仅仅须要一句代码就能够将图片下载并设置到ImageView上。

Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);

2.主要特点

2.1Adapter downloads

使用ListView,GridView的时候,自己主动检測Adapter的重用(re-use),取消下载,使用缓存。

@Override public void getView(int position, View convertView, ViewGroup parent) {
SquaredImageView view = (SquaredImageView) convertView;
if (view == null) {
view = new SquaredImageView(context);
}
String url = getItem(position); Picasso.with(context).load(url).into(view);
}

2.2图像处理与变换

将图像进行变换,以更好的适应布局控件等,减小内存开销。

Picasso.with(context)
.load(url)
.resize(200, 200)
.centerCrop()
.into(imageView)

当然,我们也能够写自己的变换类,可是必须实现Transformation接口,如:

/**
* 自己定义接口,实现图像缩小为原来的一半
*/
public class CropSquareTransformation implements Transformation {
@Override
public Bitmap transform(Bitmap source) {
int size = Math.min(source.getWidth(), source.getHeight());
int x = (source.getWidth() - size) / 2;
int y = (source.getHeight() - size) / 2;
Bitmap result = Bitmap.createBitmap(source, x, y, size, size);
if (result != source) {
source.recycle();
}
return result;
} @Override
public String key() {
return "square()";
}
}

然后设置transform方法就能够了:

Picasso.with(this).load("http://i.imgur.com/DvpvklR.png")
.transform(new CropSquareTransformation()).into(iv_test2);

效果图例如以下:

2.3。支持设置载入之前的图片,和载入失败后的图片。

如:

Picasso.with(this)
.load("http://i.imgur.com/DvpvklR.png")
.placeholder(R.drawable.abc)
.error(R.drawable.ic_launcher)
.transform(new CropSquareTransformation())
.into(iv_test1);

ImageView创建时显示abc.png,假设载入成功,显示的是DvpvklR.png,假设载入失败,显示ic_launcher.png.

2.4支持载入本地图片和sdcard中的图片文件等。

Picasso.with(context).load(R.drawable.landing_screen).into(imageView1);
Picasso.with(context).load(new File(...)).into(imageView2);

Picasso下载地址:http://square.github.io/picasso/

未经同意不得用于商业目的

android:强大的图片下载和缓存库Picasso的更多相关文章

  1. android:强大的图像下载和缓存库Picasso

    1.Picasso一个简短的引论 Picasso它是Square该公司生产的一个强大的图像下载并缓存画廊.官方网站:http://square.github.io/picasso/ 仅仅须要一句代码就 ...

  2. Picasso – Android系统的图片下载和缓存类库

    Picasso – Android系统的图片下载和缓存类库 Picasso 是Square开源的一个用于Android系统下载和缓存图片的项目.该项目和其他一些下载图片项目的主要区别之一是:使用4.0 ...

  3. 【转】Picasso – Android系统的图片下载和缓存类库

    来源:http://blog.chengyunfeng.com/?p=492 另一篇参考:http://blog.csdn.net/xu_fu/article/details/17043231 Pic ...

  4. android开源项目:图片下载缓存库picasso

    picasso是Square公司开源的一个Android图形缓存库,地址http://square.github.io/picasso/,可以实现图片下载和缓存功能. picasso有如下特性: 在a ...

  5. Android图片下载以及缓存框架

    实际开发中进行图片下载以及缓存的框架 介绍一下开发中常见图片加载框架的使用和对比一下优缺点. 1.Picasso 框架 在Android中开发,常需要从远程获取图片并显示在客户端,当然我们可以使用原生 ...

  6. (源代码分析)Android-Universal-Image-Loader (图片异步载入缓存库)的使用配置

    转载请注明出处:http://blog.csdn.net/u011733020 前言: 在Android开发中,对于图片的载入能够说是个老生常谈的问题了,图片载入是一个比較坑的地方.处理不好,会有各种 ...

  7. android-------非常好的图片加载框架和缓存库(Picasso)

    Picasso是Square公司开源的一个Android图形缓存库, 可以实现图片加载(本地和网络)和缓存功能. 地址:http://square.github.io/picasso/ jar包下载: ...

  8. picasso_强大的Android图片下载缓存库

    tag: android pic skill date: 2016/07/09 title: picasso-强大的Android图片下载缓存库 [本文转载自:泡在网上的日子 参考:http://bl ...

  9. picasso-强大的Android图片下载缓存库

    编辑推荐:稀土掘金,这是一个针对技术开发者的一个应用,你可以在掘金上获取最新最优质的技术干货,不仅仅是Android知识.前端.后端以至于产品和设计都有涉猎,想成为全栈工程师的朋友不要错过! pica ...

随机推荐

  1. 我为什么放弃Go语言

    有好几次,当我想起来的时候,总是会问自己:我为什么要放弃Go语言?这个决定是正确的吗?是明智和理性的吗?事实上我一直在认真思考这个问题. 开门见山地说,我当初放弃Go语言(golang),就是由于两个 ...

  2. ping不通的几种可能原因

    平时使用中常常会碰到ping不通的情况,ping不通的原因有非常多,比方路由设置问题,比方网络问题,下面列出几点原因:      1.太心急.即网线刚插到交换机上就想Ping通网关,忽略了生成树的收敛 ...

  3. hdu 2822 Dogs(优先队列)

    题目链接:hdu2822 会优先队列话这题很容易AC.... #include<stdio.h> #include<string.h> #include<queue> ...

  4. 函数内部用setTimeout()调用自身函数相当于setInterval()

    本来setTimeout(function(){},time)只执行了一次function,但是当 function demo() { alert(1); setTimeout('demo()' ,5 ...

  5. MongoDB学习笔记05

    count 返回集合中文档数量文档数量 db.foo.count() db.foo.count({}) distinct用来找出给定键的所有不同的值,使用时必须指定集合和键 db.runCommand ...

  6. Sql语句不能识别Go的解决办法(动态创建表的触发器)

    问题来源 用sqlserver直接打开sql文本,执行没问题,但是当用Sqlcommand类执行cmdtext命令文本时总是失败报错. 原因分析及解决 用数据库直接执行sql语句没问题,甚至还可以用G ...

  7. NPOI通过DataTable导出和读取Excel

    Excel导入及导出问题产生: 从接触.net到现在一直在维护一个DataTable导出到Excel的类,时不时还会维护一个导入类.以下是时不时就会出现的问题: 导出问题: 如果是asp.net,你得 ...

  8. 初识Treap

    Treap,简单的来说就是Tree+Heap,是一颗平衡树,每个节点有两个信息:1.key:当前节点的关键字 :2.fix:当前节点优先级.key满足二叉排序数的性质,即左儿子都比当前节点小,右儿子都 ...

  9. 几个STL算法:includes,set_difference、set_intersection、set_symmetric_difference、set_union, pre_permutation, next_permutation

    includes: 测试有序序列中是否包含另一个序列的全部元素. template<class inputIterator1, class inputIterator2> bool inc ...

  10. C# 文件/文件夹压缩

    一.ZipFile ZipFile类用于选择文件或文件夹进行压缩生成压缩包. 常用属性: 属性 说明 Count 文件数目(注意是在ComitUpdat之后才有) Password 压缩包密码 Siz ...