美文网首页
Picasso加载圆角图片

Picasso加载圆角图片

作者: GamePlayer | 来源:发表于2017-04-07 11:38 被阅读0次

    使用Picasso加载自定义圆角的圆形图片

    private void loadRoundImg(String url, ImageView img, final int corner,int width,int height) {      
               Picasso.with(context).load(url).error(R.drawable.shangcheng).resize(width,height).placeholder(R.drawable.shangcheng).transform(new Transformation() {
                @Override
                public Bitmap transform(Bitmap source) {
                    final Paint paint = new Paint();
                    paint.setAntiAlias(true);
                    paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
    
                    Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
                    Canvas canvas = new Canvas(output);
                    canvas.drawRoundRect(new RectF(0, 0, source.getWidth(), source.getHeight()), corner, corner, paint);
                    if (source != output) {
                        source.recycle();
                    }
                    return output;
                }
    
                @Override
                public String key() {
                    return "circle";
                }
            }).into(img);
        }
    

    相关文章

      网友评论

          本文标题:Picasso加载圆角图片

          本文链接:https://www.haomeiwen.com/subject/xyqhattx.html