首页 技术 正文
技术 2022年11月15日
0 收藏 794 点赞 2,369 浏览 1918 个字

1.Picasso一个简短的引论

Picasso它是Square该公司生产的一个强大的图像下载并缓存画廊。官方网站:http://square.github.io/picasso/

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

Picasso.with(context).load("https://img.zhankr.net/rvg4j01zydk197882.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("https://img.zhankr.net/rvg4j01zydk197882.png")
.transform(new CropSquareTransformation()).into(iv_test2);

效果图例如以下:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvTlVQVGJveVpIQg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center” alt=”” />

2.3。

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

如:

Picasso.with(this)
.load("https://img.zhankr.net/rvg4j01zydk197882.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/

它可能不被用于商业目的,未经同意

版权声明:本文博主原创文章。博客,未经同意不得转载。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,965
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,486
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,331
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,114
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,747
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,781