Picasso的封装(二)

news/2024/7/7 15:14:45
public class PicassoUtils {

    //默认加载图片
    public static void loadImaheView(Context mContext, String url, ImageView imageView) {
        Picasso.with(mContext).load(url).into(imageView);
    }

    //默认加载图片(指定大小)
    public static void loadImageViewSize(Context mContext, String url, int width, int height, ImageView imageView) {
        Picasso.with(mContext).load(url).config(Bitmap.Config.RGB_565).resize(width, height).centerCrop().into(imageView);
    }

    //加载图片有默认图片
    public static void loadImageViewHolder(Context mContext, String url, int loadImg,
                                           int errorImg, ImageView imageView) {
        Picasso.with(mContext).load(url).placeholder(loadImg).error(errorImg)
                .into(imageView);
    }

    //裁剪图片
    public static void loadImageViewCrop(Context mContext, String url,ImageView imageView){
        Picasso.with(mContext).load(url).transform(new CropSquareTransformation()).into(imageView);
    }

    //按比例裁剪 矩形
    public static 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 "lgl";
        }
    }

}


http://www.niftyadmin.cn/n/3649410.html

相关文章

如何创建您的第一个Visual Studio代码扩展

介绍 (Introduction) Visual Studio Code is a code editor from Microsoft available on Windows, Linux, and macOS. It offers extensions that you can install through the Visual Studio Code MarketPlace for additional features in your editor. When you can’t find…

网站添加免费SSL证书——HTTPS协议

在添加证书之前首先了解两个概念:SSL和HTTPS。 ▶ SSL(Secure Sockets Layer 安全套接层),及其继任者传输层安全(Transport Layer Security,TLS)是为网络通信提供安全及数据完整性的一种安全协议。TLS与SSL在传输层与应用层之间对网络连接进行加密。 ▶ …

使用React Native Web构建适合移动设备的Web应用

介绍 (Introduction) Over the years, building web applications that are mobile friendly has become easier with the advent of media queries and the introduction of service workers. Using media queries, we could make web applications that different shapes whe…

sql server和Navicat使用遇到错误解决办法

sql server忘记密码和用户名:http://www.cnblogs.com/xushining/p/3752667.html navicat连接失败:http://blog.csdn.net/lsd123/article/details/5548827

afinal框架(FinalAcitivity,FinalBitmap,FinalDb,FinalHttp 四大模块)

github下载地址:https://github.com/yangfuhai/afinal Afinal是一个android的ioc,orm框架,内置了四大模块功能:FinalAcitivity,FinalBitmap,FinalDb,FinalHttp。通过finalActivity,我们可以通过注解的方式进行绑定ui和…

[WiX]我的第一个WiX安装脚本

我的第一个WiX安装脚本 WiX的Wiki:WiX 代表 Windows Installer Xml (WiX) toolset 它是建立Windows Installer的XML toolset (MSI) 包裹从XML 文件。它支持开发商集成他们的发布过程建立MSI 和MSM 设定包裹的命令行环境。内部结构Wix 由四份组成: 蜡烛、光、Lit 和…

WordPress添加侧栏小工具-博客统计(网站统计)

WordPress侧边栏“博客统计”小工具的制作方法。首先要下载cztcms.zip文件,解压得到一个PHP文件。蓝奏云地址:▶ cztcms.zip 1、将这个PHP文件放到主题目录下。打开主题目录下的function.php,在最后一个 ?> 前插入以下代码: i…

every 和some_如何使用.every()和.some()操纵JavaScript数组

every 和some介绍 (Introduction) ES5 and ES6 brought many changes to JavaScript, including better ways of working with a collection of data expressed as arrays. While the language has significantly improved support for declarative data manipulation on array…