android:强大的图片下载和缓存库Picasso
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的更多相关文章
- android:强大的图像下载和缓存库Picasso
1.Picasso一个简短的引论 Picasso它是Square该公司生产的一个强大的图像下载并缓存画廊.官方网站:http://square.github.io/picasso/ 仅仅须要一句代码就 ...
- Picasso – Android系统的图片下载和缓存类库
Picasso – Android系统的图片下载和缓存类库 Picasso 是Square开源的一个用于Android系统下载和缓存图片的项目.该项目和其他一些下载图片项目的主要区别之一是:使用4.0 ...
- 【转】Picasso – Android系统的图片下载和缓存类库
来源:http://blog.chengyunfeng.com/?p=492 另一篇参考:http://blog.csdn.net/xu_fu/article/details/17043231 Pic ...
- android开源项目:图片下载缓存库picasso
picasso是Square公司开源的一个Android图形缓存库,地址http://square.github.io/picasso/,可以实现图片下载和缓存功能. picasso有如下特性: 在a ...
- Android图片下载以及缓存框架
实际开发中进行图片下载以及缓存的框架 介绍一下开发中常见图片加载框架的使用和对比一下优缺点. 1.Picasso 框架 在Android中开发,常需要从远程获取图片并显示在客户端,当然我们可以使用原生 ...
- (源代码分析)Android-Universal-Image-Loader (图片异步载入缓存库)的使用配置
转载请注明出处:http://blog.csdn.net/u011733020 前言: 在Android开发中,对于图片的载入能够说是个老生常谈的问题了,图片载入是一个比較坑的地方.处理不好,会有各种 ...
- android-------非常好的图片加载框架和缓存库(Picasso)
Picasso是Square公司开源的一个Android图形缓存库, 可以实现图片加载(本地和网络)和缓存功能. 地址:http://square.github.io/picasso/ jar包下载: ...
- picasso_强大的Android图片下载缓存库
tag: android pic skill date: 2016/07/09 title: picasso-强大的Android图片下载缓存库 [本文转载自:泡在网上的日子 参考:http://bl ...
- picasso-强大的Android图片下载缓存库
编辑推荐:稀土掘金,这是一个针对技术开发者的一个应用,你可以在掘金上获取最新最优质的技术干货,不仅仅是Android知识.前端.后端以至于产品和设计都有涉猎,想成为全栈工程师的朋友不要错过! pica ...
随机推荐
- XNOR-Net ImageNet Classification Using Binary Convolutional Neural Networks
转载请注明出处: http://www.cnblogs.com/sysuzyq/p/6245186.html by 少侠阿朱
- Rotate It !!(思维)
Rotate It !! Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- Android 环境配置:git开启多颜色模式
git config --global color.status autogit config --global color.diff autogit config --global color.br ...
- [Protractor] Protractor Interactive with elementor
Install: npm install -g elementor Then run: webdriver-manager start Lets say if we want to test 'htt ...
- 常见maven镜像
国内连接maven官方的仓库更新依赖库,网速一般很慢,收集一些国内快速的maven仓库镜像以备用. ====================国内OSChina提供的镜像,非常不错=========== ...
- C++程序设计实践指导1.1删除序列中相同的数改写要求实现
改写要求1:改写为以指针为数据结构 #include <iostream> #include <cstdlib> using namespace std; class ARP ...
- 有关PHP中点击下载文件的小功能
最近需要在项目里加一个可以点击导出树状目录的目录结构图, 我在网上查了之后,发现基本千篇一律, 都是使用下面这种header函数, 直接去readfile() 这个文件 header('Content ...
- php getenv 和 putenv 用法
getenv 的功能是取得一个指定的环境变量. getenv('REMOTE_ADDR') 和 $_SERVER['REMOTE_ADDR'] 功能一样 但是当Web服务器API是ASAPI (IIS ...
- python运维开发(二十四)----crm权限管理系统
内容目录: 数据库设计 easyUI的使用 数据库设计 权限表Perssion 角色表Role 权限和角色关系表RoleToPermission 用户表UserInfo 用户和角色关系表UserInf ...
- 黑马程序员 1、C语言32个关键字整理分类
------Java培训.Android培训.iOS培训..Net培训.期待与您交流! ------ C语言一共有32个关键字 一.数据类型关键字(共20个) A.基本数据类型(5个)void :声明 ...