加载图片框架Picasso

官网链接,Picasso.jar附上

 Picasso.with(this)
                .load(URL)
                .placeholder(R.drawable.ic_launcher)//占位符
                .error(R.drawable.logo_wechat)//错误时显示图片
                .transform(new CropSquareTransformation())
//                .resize(500, 500)//显示大小
                .into(imageView);
可以通过接口Transformation 自定义转换为更先进的效果
 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()"; }

    }

猜你喜欢

转载自u010991855.iteye.com/blog/2228282